roughike / flutter_facebook_login

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

App crashes on IOS when firing facebookLogin.logIn(); #279

Closed marhyno closed 4 years ago

marhyno commented 4 years ago

I have a problem with app crashing on ios 13.5 iphone 8. On android everything works as expected and also on ios it was working before, but I cannot find what issue would cause app to crash without error. It just closes without error.

final result = await facebookLogin.logIn(['email']); - this is where app crashes, whole code below

flutter doctor -v
[✓] Flutter (Channel master, 1.20.0-1.0.pre.105, on Mac OS X 10.15.4 19E2269, locale en-GB)
    • Flutter version 1.20.0-1.0.pre.105 at /Users/smarcin/flutter
    • Framework revision 01e09ea8af (3 hours ago), 2020-06-18 12:34:35 -0700
    • Engine revision 965fbbed17
    • Dart version 2.9.0 (build 2.9.0-14.0.dev 2b917f5b6a)

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] Connected device (1 available)
    • iPhone 8 • 7E5F2EAC-CC4B-48AA-9142-091AD6C5834E • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-5 (simulator)

flutter run -v

[   +2 ms] Flutter run key commands.
[   +2 ms] r Hot reload. 🔥🔥🔥
[   +1 ms] R Hot restart.
[        ] h Repeat this help message.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[   +1 ms] q Quit (terminate the application on the device).
[        ] An Observatory debugger and profiler on iPhone 8 is available at: http://127.0.0.1:51453/9aES4qEcg6I=/
[+19759 ms] Service protocol connection closed.
[   +1 ms] Lost connection to device.
[   +4 ms] DevFS: Deleting filesystem on the device
(file:///Users/smarcin/Library/Developer/CoreSimulator/Devices/7E5F2EAC-CC4B-48AA-9142-091AD6C5834E/data/Containers/Data/Application/554228CF-BFB6-4F39-A4
3C-C156CE8E8366/tmp/myHorse.sk_frontendN7CJR9/myHorse.sk_frontend/)
[ +257 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[   +3 ms] "flutter run" took 136,884ms.
[ +176 ms] ensureAnalyticsSent: 169ms
[   +1 ms] Running shutdown hooks
[        ] Shutdown hook priority 4
[   +4 ms] Shutdown hooks complete
[        ] exiting with code 0

Actual code

void _facebookLogin() async {
    Loading().showLoadingDialog(context);
    final facebookLogin = FacebookLogin();
    final result = await facebookLogin.logIn(['email']);  //here app crashes
    if (result.accessToken == null ){
      Navigator.pop(context);
      return;
    }
    final token = result.accessToken.token;
    final graphResponse = await http.get(
        'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${token}');
    final profile = jsonDecode(graphResponse.body);
    Navigator.pop(context);
    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        var data = {
          'email': profile['email'].toString(),
          'id': profile['id'].toString(),
          'name': profile['name'].toString(),
          'token': token.toString()
        };
        var res = await Network().postData(data, '/auth/loginFacebook', context, "Nepodarilo sa prihlásiť pomocou Facebook-u.");
        if (res == null) {
          return;
        }
        var body = json.decode(res.body);
        if (body['status'] == 200) {
          SharedPreferences localStorage = await SharedPreferences.getInstance();
          localStorage.setString('token', json.encode(body['access_token']));
          localStorage.setString('user', json.encode(body['user']));
          Navigator.pushNamedAndRemoveUntil(
              context, '/myhorses', (Route<dynamic> route) => false);
        } else if (body['status'] == 401 && body['message'] == 'Duplicate email.') {
          _showMsg("Takýto užívateľ už existuje, prihláste sa pomocou Gmailu alebo heslom.");
        } else {
          _showMsg("Nepodarilo sa prihlásiť pomocou Facebooku. Skúste znovu.");
        }
        break;
      case FacebookLoginStatus.cancelledByUser:
        Navigator.pop(context);
        return;
        break;
      case FacebookLoginStatus.error:
        _showMsg("Nepodarilo sa prihlásiť pomocou Facebooku. Skúste znovu.");
        return;
        break;
    }
  }
marhyno commented 4 years ago

Damn, my fault, I accidentaly overwrote info.plist with some other code, check if your info.plist is as is in the tutorial

misaelriojasftf commented 3 years ago

TY man this happened to me and thanks to you I noticed the info.plist somehow overwrote with Google Sign In