12

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.

enter image description here

Unome
  • 6,750
  • 7
  • 45
  • 87
  • While compile is it show any warning message in Xcode 7 debug area. – Manikandan D Oct 01 '15 at 22:27
  • None, which is strange, cause the other iOS9 changes all gave warning messages. Does anyone know the standard protocol to handling session and login? Perhaps I'm doing it wrong. – Unome Oct 01 '15 at 23:43
  • I'm having the same error... the result is nil. I am also getting 306 errors"NSLocalizedDescription" : "Access has not been granted to the Facebook account. Verify device settings." I haven't changed any app settings – ReduxDJ Oct 03 '15 at 01:18
  • Have you found an solution ? I have the same problem. I get the token, and FBSDKAccessToken.currentAccessToken() works perfect, but the moment I kill the app. Then nil is returned. – omarojo Sep 09 '16 at 03:31
  • I'm trying to remember what happened. I think I reinstalled the cocoa pods, and it started working again. – Unome Sep 09 '16 at 14:35
  • haha really ? I just did that.. no luck :( its driving me crazy because I have everything properly configured in the appdelegate and stuff. – omarojo Sep 10 '16 at 11:52
  • Adding the 'NSAllowArbitraryLoads' is not a decent solution. It will also allow unchecked http trafic ( ios restricts trafic to https only ) which makes the app subject to review in the appstore. I'm sure FB didn't intend to make it work like that. – victor Jan 29 '17 at 11:41

4 Answers4

13

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

Community
  • 1
  • 1
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
4

This happened to me also when upgrading to FBSDK 4.18.0

Downgrading to 4.17.0 solved it for me.

hansg
  • 51
  • 1
3

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

enter image description here

Manikandan D
  • 1,422
  • 1
  • 13
  • 25
0

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
    }