FaceBook第三方登录(iOS)

安装包

 pod 'FBSDKLoginKit'

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

1.创建应用


FaceBook第三方登录(iOS)_第1张图片
image.png

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


FaceBook第三方登录(iOS)_第2张图片
image.png
FaceBook第三方登录(iOS)_第3张图片
image.png

3.配置URLtypes


FaceBook第三方登录(iOS)_第4张图片
image.png

4.配置 LSApplicationQueriesSchemes

        fbapi
        fb-messenger-api
        fb-messenger-share-api
        fbauth2
        fbshareextension

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

你可能感兴趣的:(FaceBook第三方登录(iOS))