flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaging] iOS notification onResume, onLaunch callback not working

Open sandyara opened this issue 6 years ago • 29 comments

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 avatar Feb 17 '20 14:02 sandyara

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

DevarshRanpara avatar Feb 19 '20 08:02 DevarshRanpara

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

AlexandreRoba avatar Mar 01 '20 12:03 AlexandreRoba

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

iapicca avatar Mar 06 '20 16:03 iapicca

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

LOG-TAG avatar Mar 13 '20 11:03 LOG-TAG

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

Jackcui68 avatar Mar 21 '20 05:03 Jackcui68

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

yazinsai avatar Apr 02 '20 12:04 yazinsai

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?

aizazzaheer avatar Apr 23 '20 08:04 aizazzaheer

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

kristina-efros avatar Apr 27 '20 07:04 kristina-efros

any update on this?

nominator avatar May 07 '20 05:05 nominator

New Updates?

KarimMohamed20 avatar May 07 '20 15:05 KarimMohamed20

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

aloisdeniel avatar May 11 '20 07:05 aloisdeniel

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

alustrement avatar May 11 '20 08:05 alustrement

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

yazinsai avatar May 17 '20 08:05 yazinsai

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?

acoutts avatar May 20 '20 10:05 acoutts

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

ziasultan2 avatar May 31 '20 19:05 ziasultan2

has anyone worked out a fix?

MATTYGILO avatar Jun 21 '20 14:06 MATTYGILO

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

spideyduulr avatar Jul 09 '20 13:07 spideyduulr

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

emran92 avatar Jul 14 '20 00:07 emran92

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

RauschDev avatar Jul 16 '20 07:07 RauschDev

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 .

ziasultan2 avatar Jul 16 '20 13:07 ziasultan2