您已经授权Facebook,iOS
现在我有一个iOS应用程序,使用Facebook的Facebooklogin使用用户的Facebook帐户,显然你知道这一点。 这里是我用来做这个东西的代码。
-(void)loginButtonClicked { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error } else if (result.isCancelled) { // Handle cancellations } else { if ([result.grantedPermissions containsObject:@"email"]) { NSLog(@"result is:%@",result); [self fetchUserInfo]; } } }]; } - (void)fetchUserInfo { if ([FBSDKAccessToken currentAccessToken]) { NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]); [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, email, birthday, bio, location, friends, hometown, friendlists"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"resultis:%@",result); } else { NSLog(@"Error %@",error); } }]; } }
问题是当用户删除应用程序,他们安装然后再次login,Facebooklogin对话框显示“您已经授权{应用程序名称}”,用户必须单击确定返回我的应用程序。
我只想要他们只需要loginbutton,然后一个加载循环显示和成功。
任何想法做到这一点?
select-1
如果按下Login
button,请调用此
删除所有授予的权限
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/permissions" parameters:nil HTTPMethod:@"DELETE"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (error) { // Process error } else if (result.isCancelled) { // Handle cancellations } else { // call your login action and create the new session [self loginButtonClicked]; } }];
select-2
如果你想清除当前会话使用喜欢
-(void)loginButtonClicked { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logOut]; [FBSDKAccessToken setCurrentAccessToken:nil]; // then continue the same process
更新
如果你想绕过连接
-(void)loginButtonClicked { if FBSDKAccessToken.currentAccessToken != nil { // already logged in with the requested permissions } else { // start the login process } }
迅速
删除所有授予的权限
FBSDKGraphRequest(graphPath: "me/permissions", parameters: nil, HTTPMethod: "DELETE").startWithCompletionHandler({(connection: FBSDKGraphRequestConnection, result: AnyObject, error: NSError) -> Void in if error! { // Process error } else if result.isCancelled { // Handle cancellations } else { // call your login action and create the new session self.loginButtonClicked() } })
select-2
如果你想清除当前会话使用喜欢
func loginButtonClicked() { var login: FBSDKLoginManager = FBSDKLoginManager() login.logOut() FBSDKAccessToken.currentAccessToken = nil // then continue the same process }
更新
func loginButtonClicked() { if FBSDKAccessToken.currentAccessToken != nil { // already logged in with the requested permissions } else { // start the login process } }