iOS 9 Facebook Access Token is nil on future app launches - ios

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.
Login to Facebook using the FBSDKLoginButton.
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.

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

This happened to me also when upgrading to FBSDK 4.18.0
Downgrading to 4.17.0 solved it for me.

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

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
}

Related

IOS: Firebase Offline isPersistenceEnabled not working

I am using the following line in my AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
return true
}
Is this all I need to add to make my ReactJS app available offline? When I compile and run and test through Testflight - I turn off WIFI and use Airplane Mode and my app just returns a blank screen ... do I have to enable something else?
The Database.database().isPersistenceEnabled = true only ensures that data that you app has recently loaded while online is also available when you call the same API next time while offline.
If the app itself doesn't load, it is unrelated to this API call and you'll want to look at how to make a React app available while offline.

AppTrackingTransparency and SDK initialization (Facebook, Firebase...)

I'm a bit lost about AppTrackingTransparency and how to initialize some SDKs (like FB or Firebase), especially after a user first install of the app.
I don't want to show the user the app tracking transparency popup IMMEDIATELY after he installs the app because it feels too aggressive. I prefer him to go through a few steps before.
However, I know that I need to initialize some SDKs in the AppDelegate's didFinishLaunching method, i.e.:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Firebase
FirebaseApp.configure()
// FB
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
if #available(iOS 14, *) {
Settings.setAdvertiserTrackingEnabled(true)
}
return true
}
What I'm afraid of is that initializing these SDKs before showing the ATTrackingManager.requestTrackingAuthorization popup later in the app could lead to a rejection from Apple, or these SDKs to not work properly. Or can I let this code like this and call the requestTrackingAuthorization later without any issue?
Thank you
Firebase should always be the last initialization before the return true. Otherwise your code is good.

Gigya Swift Facebook and Google Native login

I am integrating gigya facebook and google to my app. The login process works when using webview, but i am having problems when i use the native apps.
For facebook, i am able to open the native app and it proceeds all the way to the screen where it says "You previously logged in with...", but upon clicking continue, it just returns to the screen where it prompts you to choose between using the facebook app or not.
For google, i have downloaded the Google app into my iOS device. But it is still using the webview with no way to use the Google app.
I am using GigyaSwift v1.0.1. Google and Facebook Wrapper is included in my Compile sources.
I have configured the following ID's into my app:
Basically GigyaSwift using GoogleSign-In SDK and it open the webView, Also you can see the implementation at GoogleWrapper.swift file.
For facebook, i apparently forgot to input some code in my AppDelegate to handle the return from Facebook native app to my app.
This is the code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//insert other code here
ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[.sourceApplication] as? String, annotation: options[.annotation])
}
For Google #Sagi Shmuel was right. Opening of Webview is the expected behavior. Thanks!

Facebook iOS App Login fails with "Session Expired" when user is not logged into the Facebook App

I have an iOS app that uses Facebook iOS Swift SDK for login. The flow is:
User clicks the login button on the app
User is redirected to the Facebook App
User logs in to the app
User is redirected back to the app when the login is successful
The above works fine when the user is already signed in to the Facebook App. However, if the user is not signed in the Facebook app and sign's in as step 3 of this workflow, the login fails with "Session Expired", "File Can't Be Opened" "This file type is unsupported"
Has anyone seen this error before? What could be causing this?
Tried this on multiple devices with the same issue. It does work on the first install but then the state somehow gets messed up and I get the same error on subsequent logins.
Code for integration with Facebook is as follows:
App Delegate application did finish launching with options call to SDK App Delegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Open URL call to SDK App Delegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
Facebook Login Button
self.loginButton = LoginButton(readPermissions: [.userFriends, .email, .publicProfile])
self.loginButton!.delegate = AppLoginButtonDelegate() // App's Login Button Delegate
self.loginStackView!.addSubview(self.loginButton!)
I've run into the same issue in our project.
Updating the Facebook App on our device resolved the issue.

Xcode 8 and Swift Could not build Objective C module 'FBSDKLoginKit'

I am having an issue when integrating the latest Facebook SDK 4.16.0 in my Swift 3.0 project using XCode 8. I manually added Facebook SDK to my project
Framework search paths
I got a compiling error saying 'Could not build module FBSDKLoginKit'.
When I navigate into FBSDKLoginKit.h, an error says 'FBSDKLoginKit/FBSDKLoginButton.h' file not found.
I searched and found this might relevant Could not build module 'FBSDKCoreKit' For FacebookSDK 4 . I tried some approaches, however, it has not worked out.
I'm appreciated your helps. Thank you.
I experienced the same issue. I was able to solve it thanks to this link. The link was actually useful in completely getting my swift project integrated with the facebook sdk. But because the post might have been a little outdated, I had to do a few things differently. One in particular is my appdelegate. Here's how mine looked when I was done.
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
FBSDKAppEvents.activateApp()
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
So basically following the link would be helpful, but you should make your appdelegate.swift, particularly the application functions and the applicationDidBecomeActive function look as I pasted above.
Also after creating the bridge-header file, adding it to the project build settings looked like this.
In the link it says it should include the directory of the project like so:
projectName/Bridging-Header.h but when I tried that, it seemed it was already looking from my project directory so it ended up looking for my header file at projectName/projectName/Bridging-Header.h which is an invalid path. So I added mine like the above screenshot instead.

Resources