skip to Main Content

Just trying to code a login using Facebook button in Flutter using flutter_facebook_auth in iOS (iPhone). The user press the button, is sent to Facebook page for login, logins, the app receives the user info (email, name, id), and sends the user to another screen.

The library and code WORKS without issues in Android emulator but, when I try to run in the iOS emulator it doesn’t work. I press the button, sends me to Facebook, login and return me to the app but the error is displayed.

Launching lib/main.dart on iPhone 14 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           15.9s
Debug service listening on ws://127.0.0.1:59856/_Os5qS_TJIM=/ws
Syncing files to device iPhone 14 Pro Max...
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(FAILED, The operation couldn’t be completed. (com.facebook.sdk.core error 8.), null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:315:18)
<asynchronous suspension>
#2      FacebookAuthPlatformImplementation.getUserData (package:flutter_facebook_auth_platform_interface/src/facebook_auth_implementation.dart:76:20)
<asynchronous suspension>

I tried to change LSApplicationQueriesSchemes using fbapi, fbauth2, fb-messenger-share-api and nothing.

I tried to change AppDelegate.swift according to this page https://developers.facebook.com/docs/ios/getting-started?locale=es_LA but i undo that because I didn’t know what i was doing. And this too https://developers.facebook.com/docs/facebook-login/ios/

Tried tis https://facebook.meedu.app/docs/5.x.x/ios/ and, obviously, this #261. This too https://www.reddit.com/r/iOSProgramming/comments/4vvaxa/the_operation_couldnt_be_completed/

I have no idea of swift, I’m just using dart.

I’m just tired to try so many things.

If you need more info don’t hesitate to request it.

What version are you using?

flutter_facebook_auth: ^5.0.7

What OS and version are you using to local deploy your application?

IOS 16.1 iPhone 14 Pro (emulator)

What platforms are you seeing the problem on?

iOS

Code .dart

Widget _facebookLoginButton(BuildContext context) {
    return TextButton(
      onPressed: () async {
        FacebookAuth.instance.login(
          permissions: ['public_profile', 'email']).then((value) {
            // Go to another screen
          }
        );
      },
      child: Text('login facebook'),
    );
  }

Info.plist (iOS)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>My App</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>myapp</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb[FACEBOOK_ID]</string>
                <string>[GOOGLE_ID]</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>FacebookAppID</key>
    <string>[FACEBOOK_ID]</string>
    <key>FacebookClientToken</key>
    <string>[CLIENT_TOKEN]</string>
    <key>FacebookDisplayName</key>
    <string>[APP NAME]</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-share-api</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIStatusBarStyle</key>
    <string></string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

Podfile (iOS)

# Uncomment this line to define a global platform for your project
platform :ios, '16.1'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

pubspec.yaml

name: myapp
description: My App
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
  sdk: '>=2.19.0 <3.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter
  video_player: ^2.4.7
  responsive_grid: ^2.1.0
  webview_flutter: ^4.0.2
  shared_preferences: ^2.0.15
  flutter_facebook_auth: ^5.0.7
  google_sign_in: ^5.4.2
  http: ^0.13.5
  custom_rating_bar: ^2.0.4
  permission_handler: ^10.2.0
  path_provider: ^2.0.11
  flutter_downloader: ^1.10.1+2
  jwt_decoder: ^2.0.1
  azure_ad_authentication: ^1.0.4

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/images/
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Montserrat
      fonts:
        - asset: fonts/Montserrat-Regular.ttf
        - asset: fonts/Montserrat-Italic.ttf
          style: italic
        - asset: fonts/Montserrat-Bold.ttf
          weight: 700
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

AppDelegate.swift (Didn’t change it, only for reference)

import UIKit
import Flutter
import flutter_downloader

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

private func registerPlugins(registry: FlutterPluginRegistry) {
    if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
       FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
    }
}

flutter doctor -v

[✓] Flutter (Channel stable, 3.7.0, on macOS 13.0.1 22A400 darwin-x64, locale
    es-419)
    • Flutter version 3.7.0 on channel stable at
      /Users/laclavees12345/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b06b8b2710 (9 days ago), 2023-01-23 16:55:55 -0800
    • Engine revision b24591ed32
    • Dart version 2.19.0
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/laclavees12345/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • AF689FEB-262D-4088-91F3-3D3E261BDB11 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

2

Answers


  1. Chosen as BEST ANSWER

    It was the clock of the Mac we are using to program. Believe it or not, it was that.

    First I changed the code like this because I was not doing the validation correctly:

    Widget _facebookLoginButton(BuildContext context) {
      return TextButton(
        onPressed: () async {
          final result = await FacebookAuth.instance.login(permissions: ['public_profile', 'email']);
            if (result.status != LoginStatus.success) {
              print(result.status);
              print(result.message);
              return;
            }
    
            final userData = await FacebookAuth.i.getUserData();
            if (userData == null) {
              return;
            }
    
            Session.save(userData['name'], userData['email']);
            Navigator.pushNamedAndRemoveUntil(context, '/welcome', (Route<dynamic> route) => false);
        },
        child: Text('login facebook'),
      );
    }
    

    By doing that, this error:

    The operation couldn’t be completed. (com.facebook.sdk.core error 8.)
    

    Became this one:

    LoginStatus.failed
    The operation couldn’t be completed. (com.facebook.sdk.core error 309.)
    

    And looking further, the problem was the clock of the Mac. The explanation is here https://github.com/facebook/facebook-ios-sdk/issues/1879 I set the date and time automatically on the Mac and it worked.


  2. The same problem happened to me. This seems to be the error of fb

    Log in failed with error: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={NSRecoveryAttempter=<FBSDKTemporaryErrorRecoveryAttempter: 0x2808c3f50>, NSLocalizedRecoverySuggestion=The server is temporarily busy, please try again., com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An unknown error has occurred., com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=500, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCodeKey=1, NSLocalizedRecoveryOptions=(
        OK
    ), com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
        body =     {
            error =         {
                code = 1;
                "fbtrace_id" = "A-1MbLDJykvSRuF-vwe4OC5";
                message = "An unknown error has occurred.";
                type = OAuthException;
            };
        };
        code = 500;
    }, com.facebook.sdk:FBSDKGraphRequestErrorKey=1}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search