使用Facebook帐户登录和注销 [英] Login and Logout with Facebook account

查看:164
本文介绍了使用Facebook帐户登录和注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将使用Facebook帐户的登录名添加到我的IOS应用程序中.我尝试安装FacebookCore pod和FacebookLogin pod.我的登录操作成功,但是当我尝试注销然后再次登录时,浏览器使用了以前的登录帐户.这是我用于登录和注销操作的代码:

I want to add login with Facebook account to my IOS app. I tried installing FacebookCore pod and FacebookLogin pod. My login action was successful but when I try to logout then login again, browser used the previous logged in account. Here is my code for login and logout action:

override func viewDidLoad() {
    super.viewDidLoad()

    let loginButton = LoginButton(readPermissions: [ .publicProfile ])
    loginButton.center = view.center
    //adding it to view
    view.addSubview(loginButton)
    loginButton.delegate = self
}

func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
    print("logged in")
    self.loginButtonClicked()
}

func loginButtonDidLogOut(_ loginButton: LoginButton) {
    print("logged out")
    AccessToken.current = nil
    UserProfile.current = nil
    FBSDKLoginManager().logOut()
}

//when login button clicked
func loginButtonClicked() {
    let loginManager = LoginManager()
    loginManager.loginBehavior = .web
    loginManager.logIn(readPermissions: [.publicProfile], viewController: self, completion: {loginResult in
        switch loginResult {
            case .failed(let error):
                print("loginnnnnn errrooorrr",error)
            case .cancelled:
                print("User cancelled login.")
            case .success(let grantedPermissions, let declinedPermissions, let accessToken):
                self.getFBUserData()
        }
    })
}

//function is fetching the user data
func getFBUserData(){
    if((FBSDKAccessToken.current()) != nil){
        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
            if (error == nil){
                self.dict = result as! [String : AnyObject]
                self.isLogin = true
                print(result!)
                print(self.dict)
            }
        })
    }
}

如何使用其他帐户登录?

How to login with another account?

推荐答案

我遇到了类似的问题,我正在接收

I had similar issue, I was receiving

您以前通过Facebook登录到[应用名称].你要不要继续吗?

you previously logged in to [app name] with Facebook. Would you like to continue?

每次注销后,我仍然想登录到我的应用程序.

every time I wanted to log in into my app even after logout.

我通过使用Facebook本地应用程序(版本177)解决了该问题.您可以在此处从应用程序注销":

I solved it by using of Facebook native app (ver. 177). You can 'log out' from your app here:

菜单标签->设置->'应用和网站'->'使用Facebook登录'->活动->选择应用->点击删除"

Menu Tab -> Settings -> 'Apps and Websites' -> 'Logged in with Facebook' -> Active -> select app -> tap Remove

这篇关于使用Facebook帐户登录和注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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