简体   繁体   English

Swift:即使从Facebook设置中删除了应用程序,也始终返回Facebook访问令牌

[英]Swift: Facebook Access Token is always returned even after removing App from Facebook settings

I'm using the Facebook SDK to login and progress through my app. 我正在使用Facebook SDK登录并通过我的应用程序进行进度。 When a user removes the app permissions from their Facebook page and then reopens the app, I want it to go to the very first view controller, which asks the user to log into Facebook. 当用户从其Facebook页面上删除该应用程序权限,然后重新打开该应用程序时,我希望它转到第一个视图控制器,该控制器要求用户登录Facebook。 However, I'm running into the problem where the user is still able to access the app even after removing the permissions. 但是,我遇到了一个问题,即使删除权限后,用户仍然可以访问该应用程序。

So, how it should work: 因此,它应该如何工作:

i) User goes to Facebook profile and removes app permissions from settings i)用户转到Facebook个人资料并从设置中删除应用程序权限

ii) User completely closes down my app from iPhone. ii)用户完全从iPhone关闭了我的应用程序。

iii) User reopens my app and the "Log into Facebook" view controller should appear. iii)用户重新打开我的应用程序,并且应该出现“登录Facebook”视图控制器。

Instead, what happens: 相反,会发生什么:

i) User goes to Facebook profile and removes app permissions from settings i)用户转到Facebook个人资料并从设置中删除应用程序权限

ii) User completely closes down my app from iPhone. ii)用户完全从iPhone关闭了我的应用程序。

iii) User reopens my app, and my app opens up in a different view controller that should only come up after user has logged in. iii)用户重新打开我的应用程序,并且我的应用程序在其他视图控制器中打开,该视图控制器仅在用户登录后才会出现。

AppDelegate.swift AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // Override point for customization after application launch.
    GMSServices.provideAPIKey("MY_API_KEY")
    GMSPlacesClient.provideAPIKey("MY_API_KEY")

    // FACEBOOK API STUFF

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    print(FBSDKAccessToken.current())

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    self.window = UIWindow(frame: UIScreen.main.bounds)

    if(FBSDKAccessToken.current() != nil){

        print(FBSDKAccessToken.current())

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "main")

        self.window?.rootViewController = initialViewController
        self.window?.makeKeyAndVisible()
    }
    else{

        print(FBSDKAccessToken.current())
        let initialViewController = storyboard.instantiateViewController(withIdentifier: "facebookLogin")

        self.window?.rootViewController = initialViewController
        self.window?.makeKeyAndVisible()
    }
    return true
}

You need to logout your session manually 您需要手动注销会话

FBSDKLoginManager().logOut() 

OR 要么

FBSDKAccessToken.current = nil
FBSDKProfile.current = nil

A solution is to refresh token every time your user start using the app when you delete your app from "Logged in with Facebook" you will receive error "The operation couldn't be completed. (com.facebook.sdk.core error 10.)" so you can then sign out and make your user sign in once again 一种解决方案是,当您从“使用Facebook登录”删除应用程序时,每次您的用户开始使用应用程序时,都会刷新令牌,您将收到错误消息“操作无法完成。(com.facebook.sdk.core错误10。 )”,这样您就可以退出并让您的用户再次登录

FBSDKAccessToken.refreshCurrentAccessToken { (_, _, error) in
            if error != nil {
                print(error!.localizedDescription)
                try! Auth.auth().signOut()
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使从Facebook应用程序设置中删除了应用程序,用户仍然可以访问应用程序 - User able to access app even after removing app from Facebook App Settings 即使从Facebook设置中删除了应用程序,AccessToken仍然存在 - AccessToken still exists even after removing an app from Facebook settings 用户在应用程序上使用“使用Facebook登录”后,如何访问Facebook访问令牌? - How to access a Facebook access token after a user has used “log in with Facebook” on an app? 应用被杀死后保持Facebook访问iOS Swift - Keep Facebook access after app is killed iOS Swift 请求访问令牌时来自Facebook App的未知错误 - Unknown error from Facebook App while requesting access token 使用Facebook iOS SDK获取应用访问令牌 - Get App access token with Facebook iOS SDK 有什么方法可以从Facebook iOS SDK返回的访问令牌中提取会话密钥? - Any way to pull out session key from access token returned by Facebook iOS SDK? Facebook 登录设置:“启用客户端访问令牌流”开关在哪里? - Facebook Login settings : Where is the "Enable Client Access Token Flow" switch? 从Phonegap FaceBook插件获取访问令牌 - Get access token from Phonegap FaceBook plugin 使用Facebook的Access_token进行Rails身份验证 - Rails Authentication with Access_token from Facebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM