iOS 9 Facebook Access Token is nil on future app launches

扶醉桌前 提交于 2019-12-03 12:03:20

问题


After the recent iOS 9 update, along with updates to the Facebook SDK (4.6.0), I'm finding that my login session is no longer persisting between app launches.

My flow so far has been pretty simple.

  1. Login to Facebook using the FBSDKLoginButton.
  2. On future View's and Launches check the FBSDKAccessToken.currentAccessToken() to be able to then use Facebook in the app.

What I'm finding is after the recent updates my AccessToken is now showing up as nil if I close and start the app again. This is a major issue because previously, I only had to login once, and then my session was being automatically renewed.

If I'm correct, login should only occur once, and after that the app should be able to either store the info it needs to connect to Facebook in the future, or simply remain with a token that refreshes itself.

Does anyone have any ideas what might have changed to cause this after the iOS9 or 4.6.0 Facebook SDK updates? Is there properties that need to be persisted to then refresh the token in the future or is the token supposed to renew automatically? I'm near 100% positive, the intended experience with Facebook SDK is NOT to have to login on every app launch (When you restart the app, close all the way and open again).

Thanks!

Update

As requested in a response, I added an additional key into the TransportSecurity info of my Plist file. Unfortunately, no luck still.


回答1:


Even it didn't worked for me when I updated my iOS 9 but after try this solution it worked for me.

1) Add data in info.plist as shown image




回答2:


Adding this line on didFinishLaunchingWithOptions worked for me:

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

Final method looks something like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    if let accessToken = FBSDKAccessToken.currentAccessToken(){
        print(accessToken)
    }else{
        print("Not logged In.")
    }

    return true
}

Reference




回答3:


This happened to me also when upgrading to FBSDK 4.18.0

Downgrading to 4.17.0 solved it for me.




回答4:


For iOS 11 / Swift 4 you should add the following code to your AppDelegate:didFinishLaunchingWithOptions

SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)

Final code is:

import FacebookCore

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.\

        // FACEBOOK CONFIGURATION
        SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)


        return true
    }


来源:https://stackoverflow.com/questions/32896269/ios-9-facebook-access-token-is-nil-on-future-app-launches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!