[firebase_messaging] iOS notification onResume, onLaunch callback not working
We Tried creating notification in our flutter application and found it to be working perfectly fine in Android devices. When it comes to iOS device we are getting the notifications when the app is in the background or when it is not open, but on clicking them we aren't taken to the respective screens which are because the callbacks aren't called. Kindly help to fix this issue.
Versions Used: Flutter: 1.12.13+hotfix.8 firebase_messaging: 6.0.9 Minimum iOS version supported: 10.0
To Reproduce Steps to reproduce the behavior:
-
Created APNs Auth Key and Configured in Firebase
-
Enabled Capabilities
- Push Notifications
- Background Mode (Background Fetch and Remote Notifications)
-
Added below code in AppDelegate.m if (@available(iOS 10.0, *)) { [UNUserNotificationCenter currentNotificationCenter].delegate = (id
) self; } -
Added below code in main.dart for listening onResume and onLaunch callbacks
_firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print('on message $message'); }, onResume: (Map<String, dynamic> message) async { print('on resume $message'); }, onLaunch: (Map<String, dynamic> message) async { print("OnLaunch Message"); }, ); _firebaseMessaging.getToken().then((token) { print("NOTIFY TOKEN ${token}"); });
Note: I could not find the solution in #935 #1757 #1677 #23293
Facing same issue, getting notification if app is not open on screen. I want to redirect user to specific screen on notification click, but i am getting 3 different cases for notification
1. If app is in foreground
I don't get notification.
2. If app is in background (Not terminated)
I get notification, but on notification click unable to redirect to specific screen.
3. If app is terminated
I get notification, and on notification click i am able to redirect to specific screen. (I want this to be happen in all above cases)
Here is more detail of my issue.
Edit
This one worked for me, now i am able to redirect user in any case.
as he suggests to remove above code from swift or objective C file and it should work.
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
Was facing the same issue. Removing the swift check as mentionned by @DevarshRanpara resolved the issue.
Hi @SandyAra did the proposed solution fix the issue for you thank you
@AlexandreRoba @SandyAra same issue exists or your comment solution working fine on firebase_messaging: ^6.0.12 ?
update:
tested working fine without that line
firebase_messaging docs are killing dev time :(
the same issue to me. but as the doc,with the code ,it still works. where is the problem?
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id
Had a similar issue -- including a minimal repo that can be used to demonstrate the erroneous behavior.
Describe the bug
Background notifications on iOS do not trigger the onLaunch / onResume methods in my Flutter app. I also do not see a badge / notification in the iOS notification center. Instead, I receive an onMessage trigger when the app is reopened
To Reproduce I created a minimal repo that exhibits this behavior
- Clone the repository here
- Run the app on the iOS simulator
- Note the
Token: xxxvalue in the Debug Console - Move the app to the background
- Trigger a notification using the following
curlcommand:
DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "<TOKEN>"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=AAAALOSN_jE:APA91bEl5CscNyXpHRrz9F4lJJnFTlt9_FPwEOvI54Q6dr2eSuS00rryGiEXkABdhfMSHimkHrybSh7r3kfhVlciBpO3HYPa_kyT34eg-JE3bWsUg479OQK5ANzCTpJ-bvktN1AWw9j4"
Expected behavior
I expect a notification to appear in the iOS Notification Center, that when clicked will trigger the onResume method. Instead, no notification is presented.
Additional context
Output of flutter doctor -v:
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-BH)
• Flutter version 1.12.13+hotfix.9 at /Users/rock/Downloads/flutter
• Framework revision f139b11009 (2 days ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/rock/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3, Build version 11C29
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.43.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1
[✓] Connected device (1 available)
• iPhone 11 • 11E9FF08-2E40-4812-A0A4-DC3B1E3398CC • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
• No issues found!
Note: I could not find the solution in #935 #1757 #1677 or #2011
Facing the same issue, I've not added the iOS 10 code in AppDelegate.swift yet not able to receive anything on onlaunch and onresume handlers. Anyone facing something similar?
Faced the same problem - instead of onResume and onLaunch callbacks an onMessage callback is received.
any update on this?
New Updates?
Any news? This is a really blocking issue I'm facing too. 😟
+1 This bug is blocking the release of our product, thank you for your reactivity.
@iapicca the fix doesn't work. Please share an update with everyone on this thread.
In my case I've got onMessage and onResume working as expected, but onLaunch does not fire in iOS. All 3 handlers working as expected in Android.
I have had a lot of issues with firebase messaging in iOS, and there are a ton of open issues about this. Is there another library that works as expected that we can use?
in my version v1.12.13+hotfix.9 fcm not working at all. before update it works without any problem. and now it's not giving any message but local notification working only. It's terrible lots of error in every version that really sucks that's why I stopped upgrading
has anyone worked out a fix?
has anyone worked out a fix????????
I'm on firebase_messaging: ^6.0.16
onResume and onLaunch on iOS is working. It works only when I click on the notification banner, but not when I click on the app icon. Is that an expected behaviour ?
Also the banner on the notification centre or lock screen wasn't showing up until I uploaded the app on Testflight.
Badge wasn't showing up until I added badge: 1 on the Additional options on cloud messaging dashboard
Here's my code:
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on Message: $message');
if (Platform.isIOS) {
_title = message['title'];
_message = message['body'];
} else {
_title = message['notification']['title'];
_message = message['notification']['body'];
}
}, onResume: (Map<String, dynamic> message) async {
print('on Resume $message');
if (Platform.isIOS) {
_title = message['title'];
_message = message['body'];
} else {
_title = message['data']['title'];
_message = message['data']['body'];
}
}, onLaunch: (Map<String, dynamic> message) async {
print('onLaunch $message');
if (Platform.isIOS) {
_title = message['title'];
_message = message['body'];
} else {
_title = message['data']['title'];
_message = message['data']['body'];
}
});
Same problem for me, this bug is blocking the release of our product.
Check your configuration and rebuild again
On Thu, Jul 16, 2020 at 1:38 PM Marco Rausch [email protected] wrote:
Same problem for me, this bug is blocking the release of our product.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FirebaseExtended/flutterfire/issues/2011#issuecomment-659219785, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQSUSDO2GJZRSM2FNNWLXTR32U7VANCNFSM4KWSQRCQ .