roughike / flutter_facebook_login

A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.
BSD 2-Clause "Simplified" License
405 stars 331 forks source link

no login dialog on iOS; works fine on Android #234

Closed robtong21 closed 4 years ago

robtong21 commented 4 years ago

I have ^2.0.1 of flutter_facebook_login plugin in pubspec.yml.

I've registered my app with Facebook according to the FB developer iOS docs, following steps 1, 3 & 4.

I enabled Facebook signin on Firebase, adding the OAuth Redirect URI from Firebase to the Facebook Login settings in the Facebook dashboard for the app.

My auth code when clicking the FB login button:


  Future<User> signInWithFacebook() async {
    final facebookLogin = FacebookLogin();
    final result = await facebookLogin.logInWithReadPermissions(
      ['public_profile'],
    );
    if (result.accessToken != null) {
      final authResult = await _firebaseAuth.signInWithCredential(
        FacebookAuthProvider.getCredential(
          accessToken: result.accessToken.token,
        ),
      );
      return _userFromFirebase(authResult.user);
    } else {
      throw PlatformException(
        code: 'ERROR_ABORTED_BY_USER',
        message: 'Sign in aborted by user',
      );
    }
  }```

Here is my Info.plist:
<img width="558" alt="Screen Shot 2020-02-04 at 12 39 21 AM" src="https://user-images.githubusercontent.com/23218836/73720871-98e93a00-46e8-11ea-8ab6-3c35e119adb1.png">

When I run an iOS simulator on Android Studio and click the login button, I do not get the login dialog, and I get this console message:
```Falling back to storing access token in NSUserDefaults because of simulator bug
    [C5.1 F2C14466-F344-4ACC-9E0B-E7FD60D2AC5A 2605:6000:1525:880d:1501:5d0c:1d99:b5d.61158<->2a03:2880:f034:112:face:b00c:0:2.443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 0.169s, DNS @0.000s took 0.004s, TCP @0.004s took 0.037s, TLS took 0.040s
    bytes in/out: 3938/2890, packets in/out: 8/10, rtt: 0.052s, retransmitted packets: 0, out-of-order packets: 0```

When I run in XCode, I do not get the login dialog and I get these console messages:
```2020-02-04 01:36:12.420411-0600 Runner[78781:7303740] -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2020-02-04 01:36:12.420705-0600 Runner[78781:7303740] Falling back to storing access token in NSUserDefaults because of simulator bug
2020-02-04 01:36:12.422583-0600 Runner[78781:7303740] -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"```

When I try to login to Facebook on Android, no problems.

Please help!
Gursewak-Uppal commented 4 years ago

Latest version 3.0.0 solved your problem

For version 2.0.1

As per the issue list for the plugin this is a bug for iOS 13 (https://github.com/roughike/flutter_facebook_login/issues/195)

Use the device_info package and you can put the following check for the iOS 13 device so the rest of the world enjoys the native view

 if (Platform.isIOS){
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
  String iosSystemVersion = iosInfo.systemVersion;

  if (iosSystemVersion.startsWith('13')){
     print('Running on IOS version $iosSystemVersion. Forcing facebook login to be 
webViewOnly');
     _facebookSignIn.loginBehavior = FacebookLoginBehavior.webViewOnly;
  }
} 
robtong21 commented 4 years ago

Thank you very much, @Gursewak-Uppal. I saw that issue you referred to but didn't think it applied to my situation.