Facebook登出在ios的新的SDK V.4.1.0中不起作用? [英] Facebook Logout is not working in new SDK V.4.1.0 in ios?

查看:156
本文介绍了Facebook登出在ios的新的SDK V.4.1.0中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友我想将Facebook集成到我的应用程序中,以便我下载新的Facebook SDK v.4.1.0,对于Facebook登录按钮,使用类别 FBSDKLoginButton 作为以下代码在Swift中。

  if(FBSDKAccessToken.currentAccessToken()!= nil)
{
/ /用户已经登录,进行下一个视图控制器等工作。

//或显示注销按钮
let loginView:FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view。 center
loginView.readPermissions = [public_profile,email,user_friends]
loginView.delegate = self
self.returnUserData()
}
else
{
let loginView:FBSDKLoginButton = FBSDKLoginButton()
self.loginButtonDidLogOut(loginView)
self.view.addSubview(loginView)
loginView.center = self.view .center
loginView.readPermissions = [public_profile,email,user_friends]
loginView.delegate = self
}
}

如上代码所示,显示使用Facebook登录按钮。





成功登录后是显示注销按钮。当我点击退出按钮时,它的委托被调用 - 委托类 FBSDKLoginButtonDelegate



注销方法:

  func loginButtonDidLogOut(loginButton:FBSDKLoginButton!){
println(User Log Out Out)

FBSDKAccessToken.setCurrentAccessToken(nil)
FBSDKProfile.setCurrentProfile(nil)

let manager = FBSDKLoginManager()
manager.logOut()

}

在委托我清楚的标记,也称为$ code> FBSDKLoginManager类的注销功能。但每次获得用户授权屏幕。
没有登录屏幕,以便另一个用户无法使用Facebook登录。每次我必须清除浏览器历史记录。



没有清除浏览器历史记录,没有显示登录页面,以便另一个用户无法登录。



Qusetion:



撤销登录



你还可以通过拨打这个Graph API端点,让人们完全取消授权应用程序或撤消登录:
DELETE / {user-id} / permissions



例如swift:

  let deletepermission = FBSDKGraphRequest(graphPath:me / permissions /,参数:nil,HTTPMethod:DELETE)
deletepermission.startWithCompletionHandler({(连接,结果,错误) - >
println中的空虚(删除权限为\(结果))

})

但是为了完全从应用程序注销该用户将被提示重新输入凭据,请参见下文:



您必须从Facebook应用程序注销,那么只有你真的注销了,然后只有应用程序再次要求凭据。这是因为你没有在手机上登录任何地方。所以SSO规则不适用于这里。如果您只从您的应用程序注销(而不是fb一个),则会因为您的案例中的safari登录而被记录。为什么,您将收到与您已经授权此应用相同的消息。



尝试在模拟器上进行测试,当您第一次插入凭据时,safari打开,您输入的凭据将保存在safari中。所以,下一次当你注销和登录的应用程序,它不会要求凭据。因为safari提供它(或者如果你已经输入你的凭证的Facebook应用程序)



现在你打开safari并打开Facebook。你看到Facebook已经开放,并且自动地从safari获取信息,或者如果你已经安装了Facebook应用程序,那么从那里开始。所以从safari注销并重新打开您的应用程序并从应用程序注销。然后您的应用程序将再次询问凭据。


Friends I want to integrate Facebook in my App, so that I am download new Facebook SDK v.4.1.0, for Facebook login button use the class of FBSDKLoginButton as below code in Swift.

if (FBSDKAccessToken.currentAccessToken() != nil)
{
    // User is already logged in, do work such as go to next view controller.

    // Or Show Logout Button
    let loginView : FBSDKLoginButton = FBSDKLoginButton()
    self.view.addSubview(loginView)
    loginView.center = self.view.center
    loginView.readPermissions = ["public_profile", "email", "user_friends"]
    loginView.delegate = self
    self.returnUserData()
}
else
{
    let loginView : FBSDKLoginButton = FBSDKLoginButton()
    self.loginButtonDidLogOut(loginView)
    self.view.addSubview(loginView)
    loginView.center = self.view.center
    loginView.readPermissions = ["public_profile", "email", "user_friends"]
    loginView.delegate = self
 }
}

As above code there is display "Log in with Facebook" button.

After Successfully login thare is display logout button. when I click on logout button then its delegate is called - delegate class FBSDKLoginButtonDelegate

Delegate method of logout :

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    println("User Logged Out")

    FBSDKAccessToken.setCurrentAccessToken(nil)
    FBSDKProfile.setCurrentProfile(nil)

    let manager = FBSDKLoginManager()
    manager.logOut()

}

in delegate I am clear token and also called function of logout inside class of FBSDKLoginManager. But each time get authorized screen of user. Not get Login screen so that another user can't login with facebook. each time I have to clear browser history.

without clear browser history, There is not display login page so that another user can't login.

Qusetion : Facebook BUG

Each time display screen after logout :

解决方案

I am also stuck in the same place. However surfing i came to following conclusion.

First lets know the meaning of SingleSignOn:

Single sign-on (SSO) is a property of access control of multiple related, but independent software systems. With this property a user logs in once and gains access to all systems without being prompted to log in again at each of them.

i think theres some point.Why, we are not asked again to login although we have logged out? Its because on simulator the credential has been saved on safari(on the first time using facebook login, your app opens safari or facebook app if installed).

The information that allows you to see the 'you have already authorized...' message lies with Facebook.In order to revoke permissions from your app, you will need to touch the Graph API. FB docs, in the 'Delete' section of https://developers.facebook.com/docs/reference/api/user/

Revoking Login

You can also let people completely de-authorize an app, or revoke login, by making a call to this Graph API endpoint: DELETE /{user-id}/permissions

e.g in swift:

 let deletepermission = FBSDKGraphRequest(graphPath: "me/permissions/", parameters: nil, HTTPMethod: "DELETE")
        deletepermission.startWithCompletionHandler({(connection,result,error)-> Void in            
            println("the delete permission is \(result)")

        })

But in order to logout from the app completely so that user will be prompted to re-enter credentials,see below:

You have to logout from facebook app , then only you are truly logged out and then only the app again asks for credentials.It's because you are not logged anywhere on the phone.So,SSO rule doesnot apply here. If you are logging out only from your app (not the fb one) you will get logged because of logged in from safari in your case.Thats why, you will get the same message showing you are already authorized for this app.

Try testing on simulator, while you insert the credentials for the first time then safari opens and the credentials you enter saves in safari. So,next time when you logout and login app it doesnot ask for credentials.Because safari provides it(or facebook app if you have entered your credential there)

Now you open safari and open facebook. You see facebook has already open and the info it takes from the safari automatically or if you have facebook app installed then from there. So logout from safari and reopen your app and logout from the app.Then your app will ask again credentials.

这篇关于Facebook登出在ios的新的SDK V.4.1.0中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆