Skip to content

[firebase_messaging] iOS notification onResume, onLaunch callback not working #2011

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

Closed
sandyara opened this issue Feb 17, 2020 · 29 comments
Closed
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging Stale Issue with no recent activity type: bug Something isn't working

Comments

@sandyara
Copy link

sandyara commented Feb 17, 2020

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:

  1. Created APNs Auth Key and Configured in Firebase

  2. Enabled Capabilities

    • Push Notifications
    • Background Mode (Background Fetch and Remote Notifications)
  3. Added below code in AppDelegate.m
    if (@available(iOS 10.0, *)) {
    [UNUserNotificationCenter currentNotificationCenter].delegate = (id) self;
    }

  4. 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

@sandyara sandyara added the type: bug Something isn't working label Feb 17, 2020
@DevarshRanpara
Copy link

DevarshRanpara commented Feb 19, 2020

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;
}

@AlexandreRoba
Copy link
Contributor

Was facing the same issue. Removing the swift check as mentionned by @DevarshRanpara resolved the issue.

@iapicca iapicca added the impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) label Mar 6, 2020
@iapicca
Copy link

iapicca commented Mar 6, 2020

Hi @sandyara
did the proposed solution fix the issue for you
thank you

@iapicca iapicca added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Mar 6, 2020
@LOG-TAG
Copy link

LOG-TAG commented Mar 13, 2020

@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 :(

@Jackcui68
Copy link

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) self;
}

@yazinsai
Copy link

yazinsai commented Apr 2, 2020

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

  1. Clone the repository here
  2. Run the app on the iOS simulator
  3. Note the Token: xxx value in the Debug Console
  4. Move the app to the background
  5. Trigger a notification using the following curl command:
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

@aizazzaheer
Copy link

aizazzaheer commented Apr 23, 2020

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?

@kristina-efros
Copy link

Faced the same problem - instead of onResume and onLaunch callbacks an onMessage callback is received.

@nominator
Copy link

any update on this?

@KarimMohamed20
Copy link

New Updates?

@aloisdeniel
Copy link

Any news? This is a really blocking issue I'm facing too. 😟

@alustrement
Copy link

+1 This bug is blocking the release of our product, thank you for your reactivity.

@yazinsai
Copy link

@iapicca the fix doesn't work. Please share an update with everyone on this thread.

@acoutts
Copy link

acoutts commented May 20, 2020

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?

@iapicca iapicca removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label May 20, 2020
@ziasultan2
Copy link

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

@MATTYGILO
Copy link

has anyone worked out a fix?

@spideyduulr
Copy link

has anyone worked out a fix????????

@emran92
Copy link

emran92 commented Jul 14, 2020

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'];
      }
    });

@RauschDev
Copy link

Same problem for me, this bug is blocking the release of our product.

@ziasultan2
Copy link

ziasultan2 commented Jul 16, 2020 via email

@ThomasTeoSY
Copy link

ThomasTeoSY commented Jul 28, 2020

The project I am working on is having the same issue and at last, we found that the root cause was due to format of the push notification is incorrect. I noticed that a lot of comments that I found from the internet asking people to put click_action inside the data content. But for my case, I put the click_action in the notification content and its works in my case.

Not working example:
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": ""}'

Working example:
DATA='{"notification": {"body": "this is a body","title": "this is a title", "click_action": "FLUTTER_NOTIFICATION_CLICK"}, "priority": "high", "data": {"id": "1", "status": "done"}, "to": ""}'

@MobileMon
Copy link

Its working fine for me. I suspect some of you may not be parsing the title and body correctly on iOS and that's where the error is occurring. Try using this code:

try{
     if (Platform.isAndroid) {
       if (message['notification'] != null){
         title = message['notification']['title'] ?? '';
         body = message['notification']['body'] ?? '';
       }
     }
     else if (Platform.isIOS) {
       if (message['aps'] != null){
         if (message['aps']['alert'] != null){
           title = message['aps']['alert']['title'] ?? '';
           body = message['aps']['alert']['body'] ?? '';
         }
       }
     }
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }
   catch(e){
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }

@Ranjithsp6
Copy link

Its working fine for me. I suspect some of you may not be parsing the title and body correctly on iOS and that's where the error is occurring. Try using this code:

try{
     if (Platform.isAndroid) {
       if (message['notification'] != null){
         title = message['notification']['title'] ?? '';
         body = message['notification']['body'] ?? '';
       }
     }
     else if (Platform.isIOS) {
       if (message['aps'] != null){
         if (message['aps']['alert'] != null){
           title = message['aps']['alert']['title'] ?? '';
           body = message['aps']['alert']['body'] ?? '';
         }
       }
     }
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }
   catch(e){
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }

Hai @MobileMon ,
I am parsing only data message, Is there any difference for Android and IOS on parsing data message?
In my case on launch is not working only on IOS

@vercorro
Copy link

       title = message['aps']['alert']['title'] ?? '';
       body = message['aps']['alert']['body'] ?? '';

It's now working well thanks to you buddy.

@Imgkl
Copy link

Imgkl commented Jan 4, 2021

Its working fine for me. I suspect some of you may not be parsing the title and body correctly on iOS and that's where the error is occurring. Try using this code:

try{
     if (Platform.isAndroid) {
       if (message['notification'] != null){
         title = message['notification']['title'] ?? '';
         body = message['notification']['body'] ?? '';
       }
     }
     else if (Platform.isIOS) {
       if (message['aps'] != null){
         if (message['aps']['alert'] != null){
           title = message['aps']['alert']['title'] ?? '';
           body = message['aps']['alert']['body'] ?? '';
         }
       }
     }
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }
   catch(e){
     title = title == null ? '' : title;
     body = body == null ? '' : body;
   }

Hai @MobileMon ,
I am parsing only data message, Is there any difference for Android and IOS on parsing data message?
In my case on launch is not working only on IOS

Did you find how to parse only the data message? I'm also facing the same issue.

@Imgkl
Copy link

Imgkl commented Jan 8, 2021

 if (Platform.isAndroid) {
    if (message['data'] != null) {
      screen = message['data']['screen'];
      docID = message['data']['docId'];
      title = message['data']['title'];
    }
  } else if (Platform.isIOS) {
    if (message != null) {
      screen = message['screen'];
      docID = message['docId'];
      title = message['title'];
    }
  } else {
    debugPrint("No message was received");
  }

This is how we should parse the data message.

@Pauljohnson78
Copy link

Strange one indeed this.

  • Android

All working as expected.

  • iOS device (14.3)

Receiving notification (in tray) in both instances when app is not in foreground.
onResume() - onLaunch() - onResume() all fail to fire with no errors.

  • iOS simulator

Notifications are not visible in tray (expected behaviour).
onResume() - onLaunch() - onResume() all fire correctly and contain correct data (unexpected behaviour(at least for me)).

Anyone had any luck with this one yet?

I'll keep plugging away.

@russellwheatley
Copy link
Member

russellwheatley commented Apr 23, 2021

Hey @sandyara, we're a few major versions removed since you raised this issue; 9.1.2. Could you please let me know if you see the same issue after upgrading, and following the latest documentation? The two platforms are very different on how notification are handled, and it is worth your time to carefully understand the expectations documented here.

@russellwheatley russellwheatley added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Apr 23, 2021
@google-oss-bot
Copy link

Hey @sandyara. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label May 4, 2021
@Salakar Salakar closed this as completed May 6, 2021
@firebase firebase locked and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests