user2312407
user2312407

Reputation: 67

Facebook Authentication iOS using Storyboard

Is there a good way to implement Facebook Authentication using Storyboard rather than xib files? It seems that the tutorial on the facebook developer site simply uses xib files.

Right now my code crashes at initWithNibName calls because my current project only uses Storyboard.

Thanks!

Code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    self.mainViewController = [[MyViewController alloc]
                               initWithNibName:@"MyViewController" bundle:nil];

    self.navController = [[UINavigationController alloc]
                          initWithRootViewController:self.mainViewController];
    self.window.rootViewController = self.navController;
    [self.window makeKeyAndVisible];

I'm getting this code from this site: https://developers.facebook.com/docs/ios/ios-sdk-tutorial/authenticate/

Upvotes: 0

Views: 1291

Answers (2)

user2312407
user2312407

Reputation: 67

I realized I could access my view controllers via the storyboard id's.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewConroller* myViewController = [sb instantiateViewControllerWithIdentifier:@"MyStoryboardID"];

Upvotes: 0

Joel
Joel

Reputation: 16124

That tutorial is useless if you want to use storyboard because 90% of the tutorial is about setting up your user interface (not Facebook specific stuff). If you want to perform this tutorial with storyboards then setup your own UI first, then understand what they are doing when the Login button is pressed (and Logout).

The only things you need to do in your app delegate are:

  1. Add the application:openURL:sourceApplication:annotation: method
  2. Modify applicationDidBecomeActive: as they suggest
  3. Check the state of the session when your app starts to determine if you show your login view or go straight to the main view (although you could also do this on the load of your first view).

You can put the code to open your facebook session (login) and respond to changes in the session state in the app delegate or elsewhere. Personally, I prefer to handle all the session management in a separate FB management class so as not to muddle up the app delegate with Facebook related code.

Your best bet is to just do this tutorial without storyboards to understand what they are doing and then adopt that into your own app, and/or read this page instead to understand the FBSession object.

Upvotes: 2

Related Questions