From 56228486596c744226ec6a6709b64dd917c23eed Mon Sep 17 00:00:00 2001 From: Sergio Guerrero Date: Thu, 31 Aug 2023 06:49:53 -0700 Subject: [PATCH] Fixed bug where the user is not logged in on subsequent sessions Summary: Bug reported in GitHub: https://github.com/facebook/facebook-sdk-for-unity/issues/695 "FB SDK doesn't keep user logged in on subsequent sessions". It's only happening in the last release of the SDK and on iOS according to user and partner reports. This diff fixes this issue. According to the instructions in the iOS SDK (https://github.com/facebook/facebook-ios-sdk/blob/41044df838ef3fefe600fb96b6560dc8a2b2a18a/FBSDKCoreKit/FBSDKCoreKit/ApplicationDelegate.swift#L55-L56), "Do not use the method initializeSDK if you are using the SDK within the context of the 'UIApplication' lifecycle", which is the case of the Unity SDK, "Instead use 'application(_:didFinishLaunchingWithOptions:)'" Basically, the didFinishLaunchingWithOptions method is called after state restoration has occurred (for example, when the app is launched again after it is suspended or in the background). It is needed to restore the user information, such as the access token. Reviewed By: GMc14 Differential Revision: D48560401 fbshipit-source-id: 6a6269ad8392db164638e24b04a666c71bfe5c7f --- .../Assets/FacebookSDK/SDK/Editor/iOS/FBUnityInterface.mm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/UnitySDK/Assets/FacebookSDK/SDK/Editor/iOS/FBUnityInterface.mm b/UnitySDK/Assets/FacebookSDK/SDK/Editor/iOS/FBUnityInterface.mm index 688460f1..ccdf19ff 100644 --- a/UnitySDK/Assets/FacebookSDK/SDK/Editor/iOS/FBUnityInterface.mm +++ b/UnitySDK/Assets/FacebookSDK/SDK/Editor/iOS/FBUnityInterface.mm @@ -62,7 +62,8 @@ + (void)load - (void)didFinishLaunching:(NSNotification *)notification { - + [[FBSDKApplicationDelegate sharedInstance] application:[UIApplication sharedApplication] + didFinishLaunchingWithOptions:notification.userInfo]; } - (void)didBecomeActive:(NSNotification *)notification @@ -394,9 +395,6 @@ void IOSFBSendViewHierarchy(const char *_tree ) void IOSFBInit(const char *_appId, bool _frictionlessRequests, const char *_urlSuffix, const char *_userAgentSuffix) { - // Initialize SDK first - [[FBSDKApplicationDelegate sharedInstance] initializeSDK]; - // Set the user agent before calling init to ensure that calls made during // init use the user agent suffix. [FBSDKSettings.sharedSettings setUserAgentSuffix:[FBUnityUtility stringFromCString:_userAgentSuffix]];