Facebook登录
步骤
- 注册Facebook成为开发者账号
- 在Facebook控制中心创建项目
-
pod 'FBSDKLoginKit'添加第三方库 - 配置fbId和白名单
- 添加代码
注意事项
自定义按钮登录事件
FBSDKLoginManager * loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:kRootViewController handler:^(FBSDKLoginManagerLoginResult * _Nullable result, NSError * _Nullable error) {
if(result.token){
//登陆成功
FBSDKAccessToken *accessToken = result.token;
}else{
}
}];
网页登录
- 如果使用网页登录,登录过一次后想切换其他账号必须清楚浏览器缓存
- 使用其他账号,该账户必须加入要添加到开发者项目内
添加facebook账号到开发者项目中
- 在开发者控制中心--->用户身份添加开发者
- 使用fbid或者username添加到开发者账号
Google登录
-
pod 'GoogleSignIn'添加Google登录第三方库 - 创建项目,生成ClientId和url scheme
- Xcode中plist添加URL scheme,这个可以在控制中心下载到
- 添加代码
注意事项
1.自定义登录按钮
//不遵循uiDelegate会导致应用程序崩溃
GIDSignIn *signIn = [GIDSignIn sharedInstance];
signIn.shouldFetchBasicProfile = YES;
signIn.delegate = self;
signIn.uiDelegate = self;
[signIn signIn];
2.iOS10会出现点击登录到无法弹出Google登录网页
在Googel的GIDSignInUIDelegate实现一下代码
在iOS10以上则不会出现这种问题
- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController{
[kRootViewController presentViewController:viewController animated:YES completion:nil];
}
- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController{
[viewController dismissViewControllerAnimated:YES completion:nil];
}












网友评论