简体   繁体   中英

Facebook Ios sdk logging in

I am trying to create a function with iOS facebook sdk where I will be able to login and if I am logged in I will be able to see the nslog string "logged in". However I am not seeing it the string at all. Also, the login seems to be working fine in terms of pushing button and seeing my Facebook app and pressing ok to continue. Can someone inform me on what I am doing wrong?

   -(IBAction)popButton:(id)sender {

   TUAppDelegate *appDelegate = (TUAppDelegate *)[[UIApplication sharedApplication] delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
    // if a user logs out explicitly, we delete any cached token information, and next
    // time they run the applicaiton they will be presented with log in UX again; most
    // users will simply close the app or switch away, without logging out; this will
    // cause the implicit cached-token login to occur on next launch of the application
    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // if the session isn't open, let's open it now and present the login UX to the user
    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self updateView];
    }];
}
  }
- (void)updateView{
// get the app delegate, so that we can reference the session property
  TUAppDelegate *appDelegate = (TUAppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.session.isOpen) {
    NSLog(@"Logged In");

} else {
    NSLog(@"Not Logged In");
}
}

I suspect you've missed at least step 2d, wiring the openURL back to the Facebook SDK:

https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/authenticate/

... that said, you could easily have missed more. If you are seeing your app again after login then I suspect you've added the URL scheme to your Info.plist, otherwise check that also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM