安裝包
pod 'FBSDKLoginKit'
地址:https://developers.facebook.com/
1.創(chuàng)建應(yīng)用
2.填一下信息,點(diǎn)擊上線,不然本賬號(hào)以外的賬號(hào)第三方登錄時(shí)無(wú)法獲取數(shù)據(jù)
3.配置URLtypes
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
監(jiān)聽(tīng)登錄成功后的數(shù)據(jù)回調(diào)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(fbUserInfoNoti:)
name:FBSDKProfileDidChangeNotification
object:nil];
// facebook 獲取用戶信息
- (void)fbUserInfoNoti:(NSNotification *)noti{
FBSDKProfile *profile = noti.userInfo[FBSDKProfileChangeNewKey];
}
- 5.3 發(fā)起第三方登錄
FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
[manager logOut];
[manager logInWithPermissions:@[@"public_profile",@"email"]
fromViewController:[self getRootVC]
handler:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
}];