现在我有一个iOS应用程序,使用Facebook SDK登录使用用户的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);
}
}];
}
}
问题是,当用户删除应用程序并安装然后再次登录时,facebook登录对话框显示“您已经授权{ApplicationName}”,用户必须单击“确定”才能返回我的应用程序。
我只想要他们只需要选项卡登录按钮然后加载圈显示并成功。
有任何想法吗?
答案 0 :(得分:2)
<强>选择-1 强>
如果按Login
按钮,请拨打此
删除所有授予的权限
[[[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];
}
}];
<强>选择-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()
}
})
<强>选择-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
}
}