Skip to content

Commit

Permalink
Fixed bug where the user is not logged in on subsequent sessions
Browse files Browse the repository at this point in the history
Summary:
Bug reported in GitHub: #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
  • Loading branch information
SergioGuerreroFB authored and facebook-github-bot committed Aug 31, 2023
1 parent b8db43b commit 5622848
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ + (void)load

- (void)didFinishLaunching:(NSNotification *)notification
{

[[FBSDKApplicationDelegate sharedInstance] application:[UIApplication sharedApplication]
didFinishLaunchingWithOptions:notification.userInfo];
}

- (void)didBecomeActive:(NSNotification *)notification
Expand Down Expand Up @@ -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]];
Expand Down

0 comments on commit 5622848

Please sign in to comment.