Search code examples
facebookxamarin.iosxamarinfacebook-ios-sdk

Facebook SDK for Xamarin.iOS login return issue


I'm trying to use the Facebook SDK for Xamarin.iOS(the one from Facebook, not from Octorcurve) to get the users Authed on my app.

I've followed the Sample that comes with the component from the store. The sample just works but I'm stuck after the login/permissions without firing the events to notify the viewController that we have a user logged in. I have set the plist file with the app name, id, and Url schema as requested by facebook SDK. So, the code is:

Note that I'm not creating the UI from code. I have a .xib IB file with the UI and yes, I added a view for the FBLoginView and set its custom class to FBLoginView.

AppDelegate.cs(omitted the rest of code for brevity):

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    // create a new window instance based on the screen size
    window = new UIWindow (UIScreen.MainScreen.Bounds);

    viewController = new LoginViewController ();
    navController = new UINavigationController (viewController);

    window.RootViewController = navController;
    window.MakeKeyAndVisible ();

    return true;
}

public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
    return FBSession.ActiveSession.HandleOpenURL(url);
}

public override void OnActivated (UIApplication application)
{
    FBSession.ActiveSession.HandleDidBecomeActive();
}

LoginViewController.cs(the controller for the NIB file):

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    loginView = btnLogin as FBLoginView;
    loginView.ReadPermissions = new string[] { "email"  };
    loginView.PublishPermissions = new string[]{ "publish_actions", "publish_stream", "manage_pages" };

    loginView.DefaultAudience = FBSessionDefaultAudience.Everyone;

    loginView.ShowingLoggedInUser += (sender, e) => 
        {
            var a = e;
        };

    loginView.FetchedUserInfo += (sender, e) => 
        {
            user = e.User;
        };
}

So, whis this code I have 2 issues:

  1. Note that I'm casting btnLogin as FBLoginView since idk how to set the outlet on Interface Builder to use the right type of FBLoginView... It always say that it its type wasnt found when I'm adding the Outlet in the .h file. So I just created it as UIView and did the cast on the code. This cast is valid and still working, since the permissions that I'm passing are being asked for user authorisation at the consent FB screen.

  2. The two events ShowingLoggedInUser and FetchedUserInfo never get called and the AppDelegate never call OpenUrl neither OnActivated.

Am I missing something? All I need is get the access_token that should be returned somewhere after the login. How do I get it?

I really appreciate any help.

Thanks!


Solution

  • Just to provide feedback for people...

    Suddenly, after 2 days hitting my head agains the wall, I just cleaned the project, rebuild it and restarted Xamarin STUDIO... Now the events are fired... No single thing changed and things are working...

    There are weird behaviours unexplained to me with Xamarin that just work or not, like sometime I start the app, and it just hangs on "Waiting for debugger to connect..." and nothing happens connecting to the device while in Simulator it works fine...

    Thanks