iOS Facebook Login Tutorial [closed]

2019-05-28 17:27发布

问题:

How to integrate Facebook login into an iOS app, for ALL versions?

I've scoured Google and GitHub for hours on end without a complete solution. I've also read all the documentation at Facebook and dissected the ios-facebook sample code. I have a working version for >=iOS6 but anything below that will crash (ACAccountStore doesn't exist). Currently I'm using a library called LBFacebook to login. The only downside is, again, it doesn't work for iOS5.

I'm pulling my hair out. The FacebookSDK changes every couple weeks. It would be miraculous to get this working once and for all.

回答1:

The Facebook SDK 3.1 is backwards compatible. It tries to authenticate in this order:

  1. Account Framework (ACAccount)
  2. Via the Facebook app (if installed)
  3. Via a web browser (old way)

I can confirm it works fine for me in older iOS version. If you are getting an error that ACAccountStore doesn't exist, you are doing something wrong. From the documentation:

If you haven't logged in before, depending on your version of iOS, you'll see the native login modal dialog box, be redirected to the Facebook for iOS or be redirected to Facebook in Safari to complete the auth flow.

See here. They show a picture of what it looks like in different iOS versions.

For complete tutorial see here.



回答2:

 NSString *strName= @"Mohit Thatai";
   FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
   [login
    logInWithReadPermissions: @[@"public_profile", @"email"]
    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
       if (error)
       {
          NSLog(@"Error");
       }
       else if (result.isCancelled)
       {
          NSLog(@"Cancell");
       }
       else
       {
     NSLog(@"Login Sucessfull");
// Share link text on face book
         FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
          [content setContentTitle:@"GPS Tracker"];
          [content setContentDescription:[NSString stringWithFormat:@"%@ shared an interesting link\n       This might be interesting to you: GPS Tracker for Kids",strName]];
 content.contentURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://gpsphonetrackerkids.com"]];
          [FBSDKShareDialog showFromViewController:self
                                       withContent:content
                                          delegate:nil];
       }
    }];