I was using the function FBSDKAccessToken.currentAccessToken() to retrieve the FB Token, which was working correctly, until I've migrated my app in swift 3 and the 4.17 SDK. Now, the function has been renamed to FBSDKAccessToken.current() and is nil when the app delegate is reloading. I've performed a few tests, and I managed to get the token after I've restarted my app and I've already logged in FB previously, but that's not the behavior I was expecting.
EDIT : I reverted to 4.15 and it's reworking again.
Here is the code in my AppDelegate :
func applicationDidBecomeActive(_ application: UIApplication)
{
FBSDKAppEvents.activateApp();
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> (Bool)
{
let wasHandled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application
,open:url
,sourceApplication:sourceApplication
,annotation:annotation)
if (wasHandled) {
if let fbtoken = FBSDKAccessToken.current() {
loginWithFacebook(fbtoken.tokenString);
}else{
print("no current token")
}
}
return wasHandled
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let wasHandled: Bool = FBSDKApplicationDelegate.sharedInstance().application(
app,
open: url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation]
)
if (wasHandled) {
if let fbtoken = FBSDKAccessToken.current() {
loginWithFacebook(fbtoken.tokenString);
}else{
print("no current token")
}
}
return wasHandled;
}
Thanks for your help :) Denis