-
Notifications
You must be signed in to change notification settings - Fork 4k
🐛 [firebase_messaging][firebase_auth] Data-only messages not received in iOS. Never fires anything in onMessage #3395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I notice this is printing in Xcode whenever a data message does come in (though it never makes it to
|
Upon testing the included example app, it appears to work as expected so I can only suspect mine is broken because of one of the following packages I'm using:
I notice some really odd behavior after adding print statements throughout the firebase_messaging plugin. I am not seeing this method execute ever:
|
Alright the issue is looking to be in firebase_auth. The remote notification is being swallowed up by In #if TARGET_OS_IPHONE
- (BOOL)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
if ([[FIRAuth auth] canHandleNotification:notification]) {
completionHandler(UIBackgroundFetchResultNoData);
return YES;
}
return NO;
} Then this is printed: Data messages seem to work in my app without firebase auth added, but as soon as I add firebase_auth to my pubspec (before even importing it anywhere in my project), it's then broken. |
I'm confident now the issue is firebase_auth. It appears I'm seeing some really strange versioning behavior too. None of the recent commits on firebase_auth seem to compile/work until
firebase_auth:
path: ../flutterfire/packages/firebase_auth/firebase_auth It still doesn't work (same error as before). If I add a single NSLog statement inside firebase_auth:
git:
url: https://github.com/FirebaseExtended/flutterfire.git
path: packages/firebase_auth/firebase_auth
ref: ba7124b5 It just goes back to printing the same error as before:
This has been incredibly frustrating as I've spent 8 hours now trying to pin this down. I even tried to really clean things out, but no luck:
Does anybody currently have firebase auth and messaging working together in the same project? |
cc @Salakar |
after moving to: firebase_auth: ^0.18.0+1 my onMessage foreground triggering is failing too. however, i'm not sending data messages but rather notifications. |
Here's a makefile target that can help you stay sane while debugging iOS issues given the number of things that can be cached:
Despite the weird behavior I had above where I had to add that print statement, now just checking out the repo locally:
Then setting my pubspec: firebase_auth:
path: ../flutterfire/packages/firebase_auth/firebase_auth I see data messages working now. So it appears things are broken in the But I'm noticing some inconsistent behavior: firebase_auth:
git:
url: https://github.com/FirebaseExtended/flutterfire.git
path: packages/firebase_auth/firebase_auth
ref: ba7124b5a0b24b76587cfdb6bb36afcb2427d792 Doesn't work. It just prints this again when I receive a data message:
From a pub / flutter perspective, why is there different behavior when I locally checkout the repo at a specific commit, vs specifying the exact same thing in the pubspec? Could it be something to do with the monorepo setup on flutterfire? |
What previous versions were you using that worked? This is blocking critical functionality in our production app now and I would love to find a working combo. |
When I try to go back to
Have the old versions now been removed and we can't downgrade? |
I found a workaround for anyone stuck like me. I can't believe this is the only way that works, but you need to do the following:
firebase_auth:
path: your/path/to/firebase_auth
firebase_messaging: ^7.0.0
The annoying thing is that you need to commit the firebase_auth files into your project if you want it to work in CI or on anybody else's environment. This must be some bug in pub that trying to point to the flutterfire git doesn't resolve the right files. Make sure to add a example/ Or, just delete the example folder after you copy firebase_auth in before you commit it up. |
Alright while that fixes firebases_messaging, it breaks the method swizzling because now the message never makes it to firebase_auth, so using the commit above is still broken. Here's what happens when I try phone auth now:
The data message instead comes in the firebase_messaging onMessage handler:
I'm going to try to get this to work now with swizzling disabled and see if I can at least make my app functional again.. |
Disabling method swizzling and using the below in my
firebase_auth: ^0.18.0+1
firebase_core: ^0.5.0
firebase_messaging: ^7.0.0
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
import UIKit
import Flutter
import FirebaseAuth
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
// https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass device token to auth
Auth.auth().setAPNSToken(deviceToken, type: .unknown)
// Pass device token to messaging
Messaging.messaging().apnsToken = deviceToken
return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
// https://firebase.google.com/docs/cloud-messaging/ios/receive#handle-swizzle
override func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Handle the message for firebase auth phone verification
if Auth.auth().canHandleNotification(notification) {
completionHandler(.noData)
return
}
// Handle it for firebase messaging analytics
if ((notification["gcm.message_id"]) != nil) {
Messaging.messaging().appDidReceiveMessage(notification)
}
return super.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: completionHandler)
}
// https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
override func application(_ application: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
// Handle auth reCAPTCHA when silent push notifications aren't available
if Auth.auth().canHandle(url) {
return true
}
return super.application(application, open: url, options: options)
}
}
|
@blaneyneil can you try that above and see if it works for you? |
this does indeed work - awesome job. |
Is there any solution for Objective-C? |
@guoguoguilai in each of the comments there I linked back to the firebase docs, and in those links you'll find the ObjC examples for what to implement. It's the exact same thing, just in ObjC instead of Swift. |
this works like a charm! |
Thank you, it works perfectly. You make my day!!! |
@DomingoMG you'll want to bump your project to iOS9 anyways since that changed recently in Flutter 1.22, so everyone has to make that change. |
You madman you fixed it. |
Update: Well, as I don't have the firebase authentication package, my notifications should work and are really working, I found out that simulators and emulators don't support push notifications.
Unless you have xcode from version >= 11.4 that you can simulate push. As said here: medium My appDelegate was normal with no other code added. I also didn't add the swizzling key. And I am receiving push on ios 14 in a wonderful way, both targeted messages and specific device messages. api : https://fcm.googleapis.com/fcm/send |
Hey folks, this should work now without needing to disable swizzling as set out in the migration guide. You should be able to receive data payloads on your iOS devices and I have tested on the messaging example to confirm behaviour. Closing this issue for now, will reopen if there is a reproducible bug. |
Bug report
Describe the bug
On iOS, it appears that sending a data-only message to FCM is not received at the device, even though the message is successfully sent according to FCM rest API.
This is on a real iOS device and not a simulator. Push notifications are otherwise working great - it's just data-only messages that are not doing anything in iOS. I have full functionality with onLaunch, onMessage, and onResume on iOS and Android, as long as it's a notification. Data-only is only being received on Android though.
Steps to reproduce
Note: in the following examples I've redacted the token.
This message is not received in iOS:
This one does work as expected:
It appears there's no way to receive data-only messages in iOS. It doesn't matter if the app is foregrounded or backgrounded-
onMessage
is never fired.Expected behavior
iOS should work with data messages exactly as it does in Android.
Additional context
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
The text was updated successfully, but these errors were encountered: