Facebook-sdk-for-unity: Facebook Login is not working on on iOS Unity 2018.4.22f1

Created on 6 May 2020  ·  20Comments  ·  Source: facebook/facebook-sdk-for-unity

So when I tried to login to facebook using this API FB.LogInWithReadPermissions, as soon as I hit "Continue", the webview displays for a split seconds then dismisses by itself but the transparent screen is still there blocking all the inputs. None of the callback is triggered.
So I tracked it down to these codes in openURLWithSafariViewController method in FBSDKLoginKit:

if (@available(iOS 11.0, *)) {
       if ([sender isAuthenticationURL:url]) {
              [self _setSessionCompletionHandlerFromHandler:handler];
              [self _openURLWithAuthenticationSession:url];
              return;
     }
   }
- (void)_openURLWithAuthenticationSession:(NSURL *)url
{
  Class AuthenticationSessionClass = fbsdkdfl_ASWebAuthenticationSessionClass();

  if (!AuthenticationSessionClass) {
    AuthenticationSessionClass = fbsdkdfl_SFAuthenticationSessionClass();
  }

  if (AuthenticationSessionClass != nil) {
    if (_authenticationSession != nil) {
      [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
                         formatString:@"There is already a request for authenticated session. Cancelling active SFAuthenticationSession before starting the new one.", nil];
      [_authenticationSession cancel];
    }
    _authenticationSession = [[AuthenticationSessionClass alloc] initWithURL:url
                                                           callbackURLScheme:[FBSDKInternalUtility appURLScheme]
                                                           completionHandler:_authenticationSessionCompletionHandler];
    if (@available(iOS 13.0, *)) {
      if ([_authenticationSession respondsToSelector:@selector(setPresentationContextProvider:)]) {
        [_authenticationSession setPresentationContextProvider:self];
      }
    }
    _isRequestingSFAuthenticationSession = YES;
    [_authenticationSession start];
  }
}

Basically Facebook is using ASWebAuthenticationSession for OAuth but somehow the [_authenticationSession start] went out and never returns, _authenticationSessionCompletionHandler never got triggered leaving the app hanging

Note that Facebook Login is working fine on Unity 2018.4.21f1 and older but breaks in 2018.4.22f1.
Any idea why and how to fix this?

Most helpful comment

I "fixed" this by adding a post-build processor

#if UNITY_IOS
     [PostProcessBuild(999)]
     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
     {
         string preprocessorPath = path + "/Classes/Preprocessor.h";
         string text = File.ReadAllText(preprocessorPath);
         text = text.Replace("UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 1", "UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 0");
         File.WriteAllText(preprocessorPath, text);
     }
#endif

Alternatively if you don't want to setup a post-processor the UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE flag can be turned off simply by unticking the "Render extra frame on pause" option in the iOS Player Settings area.

All 20 comments

I have the exact same problem. Using Unity 2019.3.13f1.

But I think it works with the Facebook 7.18.1

The problem appeared to me after upgrading to 7.19.2.

Encountered same problem with Unity 2019.3.9f1, we just upgraded to 7.19.2

I have the exact same problem. Using Unity 2019.3.13f1.

But I think it works with the Facebook 7.18.1

The problem appeared to me after upgrading to 7.19.2.

Will try Facebook 7.18.1 if problem will not appear.

I have the exact same problem. Using Unity 2019.3.13f1.
But I think it works with the Facebook 7.18.1
The problem appeared to me after upgrading to 7.19.2.

Will try Facebook 7.18.1 if problem will not appear.

Update: tried with v7.18.1 works. Thanks @wagenheimer for the tip. Hope this will be fix soon in with the latest SDK version.

Getting this exact issue on iOS 13.4, Unity 2019.3.13f1, both Facebook SDK 7.19.2 and 7.18.1 unfortunately. Clean Facebook SDK downgrade too. @iamAloTheGreat have you done anything besides downgrade the SDK to get it working?

its still happening on Unity 2018.4.22f1 on both latest Facebook SDK and 7.18.1

Interesting that it flashes the webview for just a second regardless of whether Safari is logged in to FB or not too.

I have same issue, it works in Unity 2019.3.7f but not 2019.3.13f1 and also not Unity 2020.1. I believe this is a Unity issue rather than Facebook issue.

I wrote on Unity Forum, please write there as well so that it gets visibility (https://forum.unity.com/threads/facebook-login-broken-in-unity-2019-3-13f1-but-works-in-2019-3-7f1.888502/).

Getting this exact issue on iOS 13.4, Unity 2019.3.13f1, both Facebook SDK 7.19.2 and 7.18.1 unfortunately. Clean Facebook SDK downgrade too. @iamAloTheGreat have you done anything besides downgrade the SDK to get it working?

@aVolnov Nope, I just tried to downgrade. But instead of importing 7.18.1 directly to the main project, I created a dummy project > imported 7.18.1 > deleted Facebook SDK folder and PlayServicesResolver in the main project (while Unity is closed) then paste the 2 folders from the dummy to the main. It somehow worked fine both iOS and Android.

@iamAloTheGreat Are you still on Unity 2019.3.9? I've tried your method on .13 and it made no difference, still not working. Will try downgrading to .9 and see if it works. This is all 3 days after I culled old Unity installs, d'oh.

Can confirm that the issue doesn't present after downgrading to 2019.3.9f1. No issues downgrading either, just had to delete the package cache from Library.

@aVolnov Yes I'm on Unity 2019.3.9. Good to know that downgrading to .9 solved your issue. But I'm not really sure if the problem is with Unity or Facebook tho.

I "fixed" this by adding a post-build processor

#if UNITY_IOS
     [PostProcessBuild(999)]
     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
     {
         string preprocessorPath = path + "/Classes/Preprocessor.h";
         string text = File.ReadAllText(preprocessorPath);
         text = text.Replace("UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 1", "UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 0");
         File.WriteAllText(preprocessorPath, text);
     }
#endif

hex's solution seems to work. Would you please explain what that UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE does?

I "fixed" this by adding a post-build processor

#if UNITY_IOS
     [PostProcessBuild(999)]
     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
     {
         string preprocessorPath = path + "/Classes/Preprocessor.h";
         string text = File.ReadAllText(preprocessorPath);
         text = text.Replace("UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 1", "UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 0");
         File.WriteAllText(preprocessorPath, text);
     }
#endif

Alternatively if you don't want to setup a post-processor the UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE flag can be turned off simply by unticking the "Render extra frame on pause" option in the iOS Player Settings area.

same issue with Unity 2018.4.23f1, so I've back to 2018.4.17f1, now all works with latest facebook's sdk 7.19.2

issue is present in Unity2019.4.0f1 LTS UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE false helped

Looks like I'm having the exact problem like @SangCrowdstar described. The webview displays for a split seconds then dismisses by itself and my game hangs.

macOS Catalina
Unity 2018.4.23f1
Facebook Unity SDK 7.20.0

Related issue? => https://github.com/facebook/facebook-sdk-for-unity/issues/289

I'm trying @mdobele's solution. Will keep posted.

I "fixed" this by adding a post-build processor

#if UNITY_IOS
     [PostProcessBuild(999)]
     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
     {
         string preprocessorPath = path + "/Classes/Preprocessor.h";
         string text = File.ReadAllText(preprocessorPath);
         text = text.Replace("UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 1", "UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 0");
         File.WriteAllText(preprocessorPath, text);
     }
#endif

Alternatively if you don't want to setup a post-processor the UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE flag can be turned off simply by unticking the "Render extra frame on pause" option in the iOS Player Settings area.

Unticking "Render extra frame on pause" works for me. Facebook Login succeeded! Thanks.

macOS Catalina
Unity 2018.4.23f1
Facebook Unity SDK 7.20.0

I "fixed" this by adding a post-build processor

#if UNITY_IOS
     [PostProcessBuild(999)]
     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
     {
         string preprocessorPath = path + "/Classes/Preprocessor.h";
         string text = File.ReadAllText(preprocessorPath);
         text = text.Replace("UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 1", "UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE 0");
         File.WriteAllText(preprocessorPath, text);
     }
#endif

Alternatively if you don't want to setup a post-processor the UNITY_SNAPSHOT_VIEW_ON_APPLICATION_PAUSE flag can be turned off simply by unticking the "Render extra frame on pause" option in the iOS Player Settings area.

Man, You just have saved my day, thanks for "Render extra frame on pause" option tips

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manofspirit picture manofspirit  ·  6Comments

charanjeet5ingh picture charanjeet5ingh  ·  6Comments

laijingfeng picture laijingfeng  ·  6Comments

bblpny picture bblpny  ·  4Comments

Duke74 picture Duke74  ·  4Comments