darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
197 stars 144 forks source link

iOS Not Receiving Callback - AppDelegate Issue #334

Open DennisAshford opened 1 year ago

DennisAshford commented 1 year ago

What version are you using?

flutter_facebook_auth: ^5.0.8

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

iOS 13

What platforms are you seeing the problem on?

iOS

pubspec.yaml

# The following line prevents the package from being accidentally published to
# pub.dev using `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 used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.08+75

environment:
  sdk: ">=2.7.0 <3.0.3"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  algolia: ^1.1.1
  auto_size_text: 3.0.0
  built_collection: 5.1.1
  built_value: ^8.4.0
  cached_network_image: 3.1.0+1
  chewie: ^1.3.4
  cloud_firestore: ^3.3.0
  cloud_functions: ^3.3.2
  dash_chat: 1.1.16
  equatable: 2.0.3
  file_picker: ^4.6.1
  firebase_analytics: 9.2.0
  firebase_auth: ^3.4.2
  firebase_core: ^1.19.2
  firebase_messaging: ^12.0.0
  firebase_storage: ^10.3.2
  flutter_facebook_auth: ^5.0.8
  flutter_rating_bar: ^4.0.1
  flutter_svg: ^1.0.3
  font_awesome_flutter: ^10.1.0
  google_fonts: ^3.0.1
  google_sign_in: ^5.4.0
  image_picker: ^0.8.5+3
  http: ^0.13.4
  intl: 0.17.0
  json_path: 0.2.1
  json_serializable: ^6.3.1
  mime_type: 1.0.0
  page_transition: ^2.0.9
  photo_view: ^0.14.0
  pie_chart:
  rxdart: ^0.27.4
  share_plus: ^4.0.4
  sign_in_with_apple: ^4.0.0
  table_calendar: 2.3.3
  timeago: ^3.2.2
  url_launcher: ^6.0.18
  video_player: ^2.4.5
  xml: 5.3.1
  xml2json: ^5.3.2
  hooks_riverpod:
  async:
  health_kit_reporter:
  hive: ^2.2.3
  hive_flutter: ^1.1.0
  synchronized: ^3.0.0+2
  flutter_screenutil: ^5.5.4
  modal_progress_hud_nsn: ^0.3.0

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.0
  badges: ^2.0.2
  firebase_dynamic_links: ^4.2.2
  carousel_slider: ^4.1.1
  image: ^3.1.3
  path: ^1.8.0
  path_provider: ^2.0.9
  social_share: ^2.3.1
  percent_indicator: 4.0.1
  smooth_page_indicator: ^1.0.0+2
  collection: ^1.15.0
  oauth1: ^2.0.0
  ffmpeg_kit_flutter_full: ^4.5.1
  #currenty pointing toward master branch as it contains onPressed function where pub does not
  readmore:
    git:
      url: https://github.com/jonataslaw/readmore
  screenshot: ^1.2.3
  firebase_ui_firestore: ^1.0.0-dev.0

dev_dependencies:
  build_runner: ^2.2.0
  built_value_generator: ^8.4.0
  flutter_launcher_icons: ^0.9.3
  flutter_linkify: ^5.0.2
  hive_generator:
  fake_cloud_firestore: ^1.3.2
  faker: ^2.1.0

  flutter_test:
    sdk: flutter

flutter_icons:
  android: true
  ios: true
  remove_alpha_ios: true
  image_path: 'assets/images/app_launcher_icon.png'

# 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.
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/fonts/
    - assets/images/
    - assets/videos/
    - assets/audios/
    - assets/lottie_animations/
    - assets/rive_animations/

  # 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: 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

Describe the Bug

iOS is not receiving the callback from facebook login token. The login flow works fine on Android, but is not finishing the login process on iOS. This is likely being overridden by the AppDelegate.swift file, but it is really unclear how to rewrite that function to allow for the callback to finish. Can the instructions be written more clearly as to what should be included in the AppDelegate.swift file? The relevant error is:

flutter: On pressed error:
NoSuchMethodError: The getter 'token' was called on null.
Receiver: null

Expected Behavior

Receive callback and finish login flow on iOS.

To Reproduce

Implemented according to instructions, but not sure how to fix the AppDelegate.swift overriding the callback function. Calling the login flow like so:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';

import 'auth_util.dart';

Future<UserCredential> facebookSignIn() async {
  if (kIsWeb) {
    FacebookAuthProvider facebookProvider = FacebookAuthProvider();

    facebookProvider.addScope('email');
    facebookProvider.setCustomParameters({
      'display': 'popup',
    });

    // Once signed in, return the UserCredential
    return await FirebaseAuth.instance.signInWithPopup(facebookProvider);
  }

  // Trigger the sign-in flow
  final LoginResult loginToken = await FacebookAuth.instance.login();

  if (loginToken.status == LoginStatus.success) {
    print('login success');
  } else {
    print('login failure');
  }
  final AccessToken result = loginToken.accessToken;

  if (result !=null) {
    print('access token is ${loginToken.accessToken.toString()}');
  } else {
    print('no access token');
  }

  // Create a credential from the access token
  final OAuthCredential facebookAuthCredential =
  FacebookAuthProvider.credential(result.token);

  // Once signed in, return the UserCredential
  return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}

Future<User> signInWithFacebook(BuildContext context) =>
    signInOrCreateAccount(context, facebookSignIn);

AppDelegate.swift file is below:

//AppDelegate.swift
import UIKit

import Flutter

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

Relevant log output

flutter: login failure
flutter: no access token
flutter: On pressed error:
NoSuchMethodError: The getter 'token' was called on null.
Receiver: null
Tried calling: token

flutter doctor -v

[✓] Flutter (Channel stable, 3.3.9, on macOS 13.2.1 22D68 darwin-x64, locale en-US)
    • Flutter version 3.3.9 on channel stable at /Users/dennisashford/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (4 months ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/dennisashford/Library/Android/sdk
    • Platform android-33, build-tools 32.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2021.3)
    • 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.13+0-b1751.21-8125866)

[✓] VS Code (version 1.59.1)
    • VS Code at /Users/dennisashford/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[✓] Connected device (4 available)
    • Nexus 5X (mobile)                • 00ba5fa08dc638b4          • android-arm64  • Android 8.1.0 (API 27)
    • Dennis Ashford’s iPhone (mobile) • 00008101-001274D83E10001E • ios            • iOS 16.3.1 20D67
    • macOS (desktop)                  • macos                     • darwin-x64     • macOS 13.2.1 22D68 darwin-x64
    • Chrome (web)                     • chrome                    • web-javascript • Google Chrome 111.0.5563.146
    ! Error: Dennis Ashford’s iPhone is busy: Fetching debug symbols for Dennis Ashford’s iPhone. Xcode will continue when Dennis Ashford’s iPhone is finished. (code -10)

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

• No issues found!

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>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>FytFeed</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>FytFeed</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>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fbappID</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>Bundle ID</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.fytfeed.fytfeed</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>FacebookAppID</key>
    <string>appID</string>
    <key>FacebookClientToken</key>
    <string>client token</string>
    <key>FacebookDisplayName</key>
    <string>FytFeed-v1-0</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fbapi20130214</string>
        <string>fbapi20130410</string>
        <string>fbapi20130702</string>
        <string>fbapi20131010</string>
        <string>fbapi20131219</string>
        <string>fbapi20140410</string>
        <string>fbapi20140116</string>
        <string>fbapi20150313</string>
        <string>fbapi20150629</string>
        <string>fbapi20160328</string>
        <string>fbauth</string>
        <string>fb-messenger-share-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
        <string>instagram-stories</string>
        <string>facebook-stories</string>
        <string>facebook</string>
        <string>instagram</string>
        <string>twitter</string>
        <string>whatsapp</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSCameraUsageDescription</key>
    <string>Turning on access to your camera allows you to upload photos and videos to your profile and posts.</string>
    <key>NSHealthShareUsageDescription</key>
    <string>In order to power the Apple Health integration, this app requires HealthKit usage</string>
    <key>NSHealthUpdateUsageDescription</key>
    <string>In order to power the Apple Health integration, this app requires HealthKit usage</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>This app needs location to store GPS data about workouts</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs location to store GPS data about workouts</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>In order to record audio for video, this app requires permission to access the microphone.</string>
    <key>NSPhotoLibraryUsageDescription</key>
  <string>Turning on access to your media library allows you to upload photos and videos to your profile and posts.</string>
    <key>NSPhotoLibraryAddUsageDescription</key>
  <string>In order to create media such as overlayed images and videos, this app requires permission to write to the photo library.</string>
    <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>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
</dict>
</plist>

Podfile (iOS)

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

# 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
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '9.6.0'
  pod 'GoogleUtilities'
  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)
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
  end
end

target 'ImageNotification' do
  use_frameworks!
  pod 'Firebase/Messaging', '>= 0'
  pod 'GoogleUtilities'
end

AndroidManifest.xml

No response

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 1 year ago

@DennisAshford Check if you already have CFBundleURLTypes or LSApplicationQueriesSchemes keys in your Info.plist. If you have, you should merge their values, instead of adding a duplicate key.

Example with Google and Facebook implementation:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fb{your-app-id}</string>
      <string>com.googleusercontent.apps.{your-app-specific-url}</string>
    </array>
  </dict>
</array>

Also for fb login you only need

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-share-api</string>
</array>
darwin-morocho commented 1 year ago

If you want to override the fb callback you can use the next function in your AppDelegate class

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
        if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId!)") && url.host ==  "authorize" {
              print("AppDelegate-> is login by facebook")
              return ApplicationDelegate.shared.application(app, open: url, options: options)
        }

        return false

  }
DennisAshford commented 1 year ago

@darwin-morocho thank you for your reply. I apologize, I am very unfamiliar with swift. I have now updated my AppDelegate.swift to this

import UIKit

import Flutter

import FBSDKCoreKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

          let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
          if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
          print("AppDelegate-> is login by facebook")
          return ApplicationDelegate.shared.application(app, open: url, options: options)

          }
          return false
    }
}

However, now it will open the app, ask for permission to sign into the app, but then it is not going back to the app to finish the login flow. Is this how the AppDelegate.swift file should look? Below is a video of the behavior. Thank you for your help!

https://user-images.githubusercontent.com/89257202/229301188-9f6e9f8d-1970-4ea7-b940-cb4f7b7a10bf.mov

darwin-morocho commented 1 year ago

@DennisAshford by default this plugin intercept the facebook callback so you first must try without this code

 override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

          let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
          if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
          print("AppDelegate-> is login by facebook")
          return ApplicationDelegate.shared.application(app, open: url, options: options)

          }
          return false
    }
darwin-morocho commented 1 year ago

Here you have a complete demo

https://github.com/darwin-morocho/flutter-facebook-auth/issues/6#issuecomment-624943909

You should remove the selected code

image
DennisAshford commented 1 year ago

@darwin-morocho I have now updated my AppDelegate.swift to the following code, however, it still is not navigating back to the original app (same behavior as the video above). Any ideas?

import UIKit
import Flutter
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)// <--- ADD THIS LINE
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    // <--- OVERRIDE THIS METHOD WITH THIS CODE
    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        if url.scheme != nil {
            let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
            if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
                 print("is login by facebook")
                 return ApplicationDelegate.shared.application(app, open: url, options: options)
            }
        }

        return false

    }
}
darwin-morocho commented 1 year ago

@DennisAshford check https://github.com/darwin-morocho/flutter-facebook-auth/issues/211#issuecomment-1013054854

DennisAshford commented 1 year ago

@darwin-morocho unfortunately the exact same behavior. Here is the AppDelegate.swift file now. It is not even coming back into the main app with the login token anymore. I should mention that I have to remove the "!" in the "fb\facebookAppId" part, or it turns the rest of the code into a string for some reason.

I should also ask, is this in the iOS/Runner/AppDelegate.swift file?

import UIKit
import Flutter
import Firebase
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
          override func application(
              _ application: UIApplication,
              didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
          ) -> Bool
          {
              FirebaseApp.configure()
              GeneratedPluginRegistrant.register(with: self)
              return super.application(application, didFinishLaunchingWithOptions: launchOptions) // YES;
          }

          override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
                  if url.scheme != nil {
                      let facebookAppId: String? = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String
                      if facebookAppId != nil && url.scheme!.hasPrefix("fb\(facebookAppId)") && url.host ==  "authorize" {
                           print("is login by facebook")
                           return ApplicationDelegate.shared.application(app, open: url, options: options)
                      }
                  }

                  return false

              }
      }

Update: after building in XCode, it will now navigate back to the main app with the AppDelegate above, but it is still not getting the token

NoSuchMethodError: The getter 'token' was called on null.
Receiver: null
Tried calling: token
darwin-morocho commented 1 year ago

@DennisAshford in the facebook documentation says that since ios 13 you must create a SceneDelegate.swift at the same level of your AppDelegate.swift and add this code

import UIKit
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
   func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }

    ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation]
    )
  }
}

For more info check https://developers.facebook.com/docs/facebook-login/ios?locale=en_US

DennisAshford commented 1 year ago

@darwin-morocho I have created a SceneDeleget.swift folder with the following code

import UIKit
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
   func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }

    ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation]
    )
  }
}

I also tried both with the original AppDelegate.swift code in the top and with the Firebase app and both are giving the exact same behavior. The token is not being transferred back into my app. Has it been confirmed that this package works on iOS 13? If so, is there any example anywhere I can work from?

darwin-morocho commented 1 year ago

@darwin-morocho I have created a SceneDeleget.swift folder with the following code

import UIKit
import FBSDKCoreKit // <--- ADD THIS LINE (first you need run  pod install)

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
   func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }

    ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation]
    )
  }
}

I also tried both with the original AppDelegate.swift code in the top and with the Firebase app and both are giving the exact same behavior. The token is not being transferred back into my app. Has it been confirmed that this package works on iOS 13? If so, is there any example anywhere I can work from?

This package works since ios 11 and the most recent versions. But is posible that you are using a dependency that has a conflict with this plugin.

You can check the example folder and replace with your credentials

DennisAshford commented 1 year ago

@darwin-morocho it works perfectly on Android, so I do not think it is a dependency conflict. I believe it has something to do with the override in AppDelegate but I cannot figure out how to get that from happening when it reopens my app. You have confirmed that package works when iOS is set to >13? The example is set to 12.0.

darwin-morocho commented 1 year ago

@darwin-morocho it works perfectly on Android, so I do not think it is a dependency conflict. I believe it has something to do with the override in AppDelegate but I cannot figure out how to get that from happening when it reopens my app. You have confirmed that package works when iOS is set to >13? The example is set to 12.0.

Yes . I have. Even You can confirm that running the example and changing 12 to 13. Also keep in mind that if you are running in a real ios device with the facebook app in that case your facebook app must be in production mode or the facebook account linked into the facebook app must be allowed to sign in in your facebook app

DennisAshford commented 1 year ago

@darwin-morocho thanks for your help. I still cannot get this to work and am having trouble getting the example to build due iOS signing issues with it. I guess I will keep trying to figure this out.

When you change the example build to iOS 13+, do you need to create a SceneDelegate.swift file to get it work?

darwin-morocho commented 1 year ago

@darwin-morocho thanks for your help. I still cannot get this to work and am having trouble getting the example to build due iOS signing issues with it. I guess I will keep trying to figure this out.

When you change the example build to iOS 13+, do you need to create a SceneDelegate.swift file to get it work?

I don't even I have installed all your dependencies in your pubspec.yaml without any error. I think the problem is in your facebook developers console.

DennisAshford commented 1 year ago

@darwin-morocho wouldn't that cause the Android flow to mess up too though?

darwin-morocho commented 1 year ago

@darwin-morocho wouldn't that cause the Android flow to mess up too though?

Keep in mind that for each platform you have one configuration in your facebook console.

DennisAshford commented 1 year ago

@darwin-morocho yes. It has been configured for both. In fact, we have been using facebook_auth on our iOS app for over a year now without problems, but we had to update to the latest version due to issues with the Android flow and that has now broken our iOS flow for some reason. Now trying to figure why. Fix one thing to break another :)

darwin-morocho commented 1 year ago

@darwin-morocho yes. It has been configured for both. In fact, we have been using facebook_auth on our iOS app for over a year now without problems, but we had to update to the latest version due to issues with the Android flow and that has now broken our iOS flow for some reason. Now trying to figure why. Fix one thing to break another :)

What version were you using?

DennisAshford commented 1 year ago

flutter_facebook_auth: ^4.4.0+1

darwin-morocho commented 1 year ago

flutter_facebook_auth: ^4.4.0+1

Could you try with 4.4.1+1

darwin-morocho commented 1 year ago

flutter_facebook_auth: ^4.4.0+1

Could you try with 4.4.1+1

Or you can try to overriding the pods version in your Podfile and use

pod 'FBSDKCoreKit', '~> 14.1.0'
pod 'FBSDKLoginKit', '~> 14.1.0'
DennisAshford commented 1 year ago

@darwin-morocho unfortunately downgrading gave me several pod dependency issues now. I am going to call in a night for the night, but try again tomorrow. I hope I can get this figured out soon :)

DennisAshford commented 1 year ago

@darwin-morocho I am actually seeing some odd behavior from iOS. First, everything works on Android and I can authenticate multiple Facebook accounts with no problem. However, on iOS, it seems my device can only authenticate a single Facebook account, and if I login into another one on the iOS device, the login token comes back null. Do you know if there is some type of limitation with Facebook accounts on iOS devices that would prevent you from authenticating multiple Facebook accounts on the app?

Bewenben commented 1 year ago

I'm having the same issue, callback always give null for some reason...

DennisAshford commented 1 year ago

I'm having the same issue, callback always give null for some reason...

I believe it has to do with limits iOS and/or Meta have on the number of tokens per device. If it works the very first time, but then you try and delete the account/re-auth on the same device, the callback fails. Eventually I came to believe it was due to trying to re-auth a new account on the same iOS device. It doesn't happen on Android.