Open DennisAshford opened 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>
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
}
@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!
@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
}
Here you have a complete demo
https://github.com/darwin-morocho/flutter-facebook-auth/issues/6#issuecomment-624943909
You should remove the selected code
@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 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
@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
@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 I have created a
SceneDeleget.swift
folder with the following codeimport 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 theFirebase
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
@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 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
@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 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.
@darwin-morocho wouldn't that cause the Android flow to mess up too though?
@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.
@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 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?
flutter_facebook_auth: ^4.4.0+1
flutter_facebook_auth: ^4.4.0+1
Could you try with 4.4.1+1
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'
@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 :)
@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?
I'm having the same issue, callback always give null for some reason...
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.
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
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: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:
AppDelegate.swift file is below:
Relevant log output
flutter doctor -v
Info.plist (iOS)
Podfile (iOS)
AndroidManifest.xml
No response
MainActivity.java
No response
MainActivity.kt
No response
index.html
No response
Info.plist (macOS)
No response