安装包
pod 'FBSDKLoginKit'
地址:https://developers.facebook.com/
1.创建应用
2.填一下信息,点击上线,不然本账号以外的账号第三方登录时无法获取数据
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
监听登录成功后的数据回调
[[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) {
}];