[英]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.