iOS Facebook Login Tutorial [closed]

六眼飞鱼酱① 提交于 2019-12-22 17:55:05

问题


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];
       }
    }];


来源:https://stackoverflow.com/questions/18555034/ios-facebook-login-tutorial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!