FaceBook第三方登录(iOS)

安装包

 pod 'FBSDKLoginKit'

地址:https://developers.facebook.com/

1.创建应用


image.png

2.填一下信息,点击上线,不然本账号以外的账号第三方登录时无法获取数据


image.png
image.png

3.配置URLtypes


image.png

4.配置 LSApplicationQueriesSchemes

        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fb-messenger-share-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>

5.代码集成

  • 5.1 Facebook模块初始化
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    [FBSDKSettings setAppID:@"44510333315xxxxxx"];
}
  • 5.2
    监听登录成功后的数据回调
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(fbUserInfoNoti:)
                                                 name:FBSDKProfileDidChangeNotification
                                               object:nil];

// facebook 获取用户信息
- (void)fbUserInfoNoti:(NSNotification *)noti{
    FBSDKProfile *profile = noti.userInfo[FBSDKProfileChangeNewKey];
}

  • 5.3 发起第三方登录
    FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
    [manager logOut];
    [manager logInWithPermissions:@[@"public_profile",@"email"]
               fromViewController:[self getRootVC]
                          handler:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
        
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容