awesome_notifications icon indicating copy to clipboard operation
awesome_notifications copied to clipboard

[iOS] "Received an invalid notification content" message is displayed in console when tapping or opening Firebase notification.

Open MaheshKumarM-SCE opened this issue 3 years ago • 23 comments

Android: Firebase notification is working fine in Android.

  • Usually FirebaseMessaging.onMessageOpenedApp is triggered when tapping on the FCM notification. But after including awesome_notification in pubspec.yaml the FirebaseMessaging.onMessageOpenedApp is not triggered when tapping on the notification.
  • And also FirebaseMessaging.instance.getInitialMessage() is not called when opening the app by tapping on the notification while app is terminated. This usually works.
  • This issue occurs only in IOS, it works fine in Android. This problem occurred after including the awesome_notification.

Please help in sorting this issue.

MaheshKumarM-SCE avatar May 19 '21 19:05 MaheshKumarM-SCE

I did a test branch to check if the problem could be solved with a little change. Try to put the declaration bellow inside your pubspec.yaml file:

  awesome_notifications: #^0.0.6+7
    git:
      url: https://github.com/rafaelsetragni/awesome_notifications.git
      ref: c968836

Also, put the code bellow inside your pubspec.yaml, to allow to use direrctely GitHub repositories in your project, bellow the tag description:

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

And finally run pub get to check if the problem is solved with this fix.

rafaelsetragni avatar May 19 '21 22:05 rafaelsetragni

Thank you so much for helping me. I checked now and I got the the warning below after tapping the notification -

Warning: UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.

MaheshKumarM-SCE avatar May 20 '21 05:05 MaheshKumarM-SCE

I did a new small improvement, because im obbligate to call completionHandler. But if i do it, i gonna cancel any other processment, including the firebase_message one.

Replace the git ref tag from c968836 to f9405a8 and execute your tests again:

  awesome_notifications: #^0.0.6+7
    git:
      url: https://github.com/rafaelsetragni/awesome_notifications.git
      ref: f9405a8

rafaelsetragni avatar May 20 '21 15:05 rafaelsetragni

Hi, can you please help me.. I tried the latest code from the git ref tag f9405a8 and I observed the following behaviour.

  1. On receiving the notification when app is in foreground or on tapping the firebase notification when app is in background, application crashed (I have attached the crash logs below)

    *thread #1, queue = 'com.google.firebase.messaging.database.rmq', stop reason = EXC_BAD_ACCESS (code=2, address=0x16ae67e18) frame #0: 0x00000001944796bc CoreFoundation__CFStringAppendBytes + 684 CoreFoundation__CFStringAppendBytes: -> 0x1944796bc <+684>: stp x25, xzr, [sp, #0x8] 0x1944796c0 <+688>: add x1, sp, #0x8 ; =0x8 0x1944796c4 <+692>: mov x0, x21 0x1944796c8 <+696>: mov w2, #0x1 Target 0: (Runner) stopped.


  1. On checking the logs, I got the error from the method saveS2dMessageWithRmqId.

    (void)saveS2dMessageWithRmqId:(NSString *)rmqId { dispatch_async(_databaseOperationQueue, ^{ NSString *insertFormat = @"INSERT INTO %@ (%@) VALUES (?)"; NSString *insertSQL = [NSString stringWithFormat:insertFormat, kTableS2DRmqIds, kRmqIdColumn]; sqlite3_stmt *insert_statement; if (sqlite3_prepare_v2(self->_database, [insertSQL UTF8String], -1, &insert_statement, NULL) != SQLITE_OK) { FIRMessagingRmqLogAndReturn(insert_statement); } if (sqlite3_bind_text(insert_statement, 1, [rmqId UTF8String], (int)[rmqId length], SQLITE_STATIC) != SQLITE_OK) { FIRMessagingRmqLogAndReturn(insert_statement); } if (sqlite3_step(insert_statement) != SQLITE_DONE) { FIRMessagingRmqLogAndReturn(insert_statement); } sqlite3_finalize(insert_statement); }); }


  1. After commenting the following lines of code, I tried once again. This time, I tapped the FCM notification, app is opened but did not navigate to correct page and also app did not crash like before but notification functionality is not working.

    if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }

MaheshKumarM-SCE avatar May 20 '21 17:05 MaheshKumarM-SCE

UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate

This class is responsible to capture the notifications actions and handle it.

Can you build a simple example app with this issue and share it with me here on GitHub? I believe this way will be more easily to understand whats going on.

rafaelsetragni avatar May 20 '21 18:05 rafaelsetragni

Hi I have setup the project with firebase notification. I havent added the firebase account setup. can you please check my project - reminderApp

MaheshKumarM-SCE avatar May 21 '21 07:05 MaheshKumarM-SCE

Hi.. Just in case If I had to add or change something in the project - reminderApp.. Please tell me

MaheshKumarM-SCE avatar May 22 '21 11:05 MaheshKumarM-SCE

No problem! I found a solution, but i need to do more tests before send it to you.

rafaelsetragni avatar May 22 '21 13:05 rafaelsetragni

Sure @rafaelsetragni... Thanks a lot

MaheshKumarM-SCE avatar May 23 '21 17:05 MaheshKumarM-SCE

Hi @rafaelsetragni, please can you help me solve this issue .. if possible can we connect and discuss the solution.

MaheshKumarM-SCE avatar May 26 '21 09:05 MaheshKumarM-SCE

I need to be honest with you. Have you ever made your sample application work?

I'm finishing up, but honestly, it was impossible to ever work once with firebase. there were too many things left to do and some others were done incorrectly, such as calling Awesome initialization twice and not passing the notification content to the delivered page.

I'm fixing it, but I need to tell you that i truly didn't understand what the problem was with your sample application that you wanted to show me. Nothing was working at all.

I gonna send to tou a sample to merge, but is not finished yet.

rafaelsetragni avatar May 26 '21 10:05 rafaelsetragni

Pull request sent: https://github.com/MaheshKumarM-SCE/reminderApp/pull/2

rafaelsetragni avatar May 26 '21 11:05 rafaelsetragni

Hi, I can imagine how you would have felt after seeing things which are not proper - such as calling Awesome initialization twice.. I still remember I fixed that.. but I didn't add the changes here.. Also, feel free to say what I did wrong or what I should do next time if it really worries you..

Finally I really want to say.. Thank you.. because "You make things happen"... I just checked now and Firebase notification is working good as expected in iOS.

For reference:
url: https://github.com/rafaelsetragni/awesome_notifications.git ref: fbee982

MaheshKumarM-SCE avatar May 26 '21 20:05 MaheshKumarM-SCE

When I click on a notification using the git branch fbee982 above, the app crashes and I get this in the console:

dnssd_clientstub read_all(9) DEFUNCT
[VERBOSE-2:FlutterObservatoryPublisher.mm(143)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
dnssd_clientstub read_all(25) DEFUNCT
[VERBOSE-2:FlutterObservatoryPublisher.mm(143)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16b677fb0)
    frame #0: 0x0000000180e4d0c0 libdyld.dylib`dyld3::closure::ObjCClassOpt::forEachClass(char const*, dyld3::Array<std::__1::pair<unsigned long, unsigned long> > const&, void (void*, bool, bool*) block_pointer) const + 8
libdyld.dylib`dyld3::closure::ObjCClassOpt::forEachClass:
->  0x180e4d0c0 <+8>:  stp    x28, x27, [sp, #0x10]
    0x180e4d0c4 <+12>: stp    x26, x25, [sp, #0x20]
    0x180e4d0c8 <+16>: stp    x24, x23, [sp, #0x30]
    0x180e4d0cc <+20>: stp    x22, x21, [sp, #0x40]
Target 0: (Runner) stopped.
Lost connection to device.

Any ideas?

jonas-zebari avatar Aug 17 '21 21:08 jonas-zebari

Hey!! I fixed it finally! When you post a notification, the body should be like;

{
    // "notification":{"title": "title","body": "body" }, DON'T USE THIS LINE EVER!
    "to": "token",
    "priority": "high",
    "data": {
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "content": {
        "payload":{
          "type": "Message",
          "userId": "123",
          "postId": "postId"
        },
        "id": 100,
        "channelKey": "basic_channel",
        "body": "body",
        "title": "title"
      }
    },
    "mutable_content" : true,
    "content_available": true
  }

Do not use the first line "notification":{"title": "title","body": "body" } when you fire a notification. It happens on iOS because of this notification data. I don't know why but it fixed on my project. Use the latest firebase messaging and firebase core packages. It will be fixed.

Cheers! 🥳

furkankurt avatar Aug 18 '21 21:08 furkankurt

@furkankurt Gettinga Type '{ title: string; body: string; }' is not assignable to type 'string'. for the content section (Using Typescript)

yassinsameh avatar Dec 20 '21 16:12 yassinsameh

i do have the same problem

  • thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16b9a7fb0) frame #0: 0x00000001963ce320 libsystem_malloc.dylibnanov2_allocate_from_block$VARIANT$mp + 4 libsystem_malloc.dylibnanov2_allocate_from_block$VARIANT$mp: -> 0x1963ce320 <+4>: stp x28, x27, [sp, #0x20] 0x1963ce324 <+8>: stp x26, x25, [sp, #0x30] 0x1963ce328 <+12>: stp x24, x23, [sp, #0x40] 0x1963ce32c <+16>: stp x22, x21, [sp, #0x50] Target 0: (Runner) stopped. Lost connection to device.

mtmfuture avatar Jan 15 '22 05:01 mtmfuture

i have same issue. when i tap a notification i got "Received an invalid notification content" message. i use latest version (0.6.20)

dmrcierhn avatar Jan 16 '22 11:01 dmrcierhn

I am having the same problem when I tap on a notification sent through Firebase: "Received an invalid notification content". I tried to change the body as @furkankurt suggested but doing that, in iOS I don't receive the notification at all when the app is in foreground. Hany suggestion? I'm using the latest version version (0.6.20)

alecisco avatar Jan 16 '22 18:01 alecisco

i am using @furkankurt body its work that i test push using https://fcm.googleapis.com/fcm/send

{
    "to": "token",
    "priority": "high",
    "data": {
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "content": {
        "payload":{
          "type": "Message",
          "userId": "123",
          "postId": "postId"
        },
        "id": 100,
        "channelKey": "basic_channel",
        "body": "body",
        "title": "title"
      }
    },
    "mutable_content" : true,
    "content_available": true
  }

putrautama007 avatar Mar 08 '22 02:03 putrautama007

@putrautama007 @furkankurt when i test with your format notification, i don't receive any notifications. It only works when i put

"notification": {
        "body" : "Sending Notification Body From Data",
     "title": "Notification Title from Data"
    }

into my data. I miss some configurations ? Do you have any ideal ? Thank you very much.

minhnhatvdl avatar Apr 11 '22 12:04 minhnhatvdl

Hi, i already answer with 'foolish' way, check it : https://github.com/rafaelsetragni/awesome_notifications/issues/132#issuecomment-1102985789

arbyazra123 avatar Apr 19 '22 19:04 arbyazra123

Hey!! I fixed it finally! When you post a notification, the body should be like;

{
    // "notification":{"title": "title","body": "body" }, DON'T USE THIS LINE EVER!
    "to": "token",
    "priority": "high",
    "data": {
      "click_action": "FLUTTER_NOTIFICATION_CLICK",
      "content": {
        "payload":{
          "type": "Message",
          "userId": "123",
          "postId": "postId"
        },
        "id": 100,
        "channelKey": "basic_channel",
        "body": "body",
        "title": "title"
      }
    },
    "mutable_content" : true,
    "content_available": true
  }

Do not use the first line "notification":{"title": "title","body": "body" } when you fire a notification. It happens on iOS because of this notification data. I don't know why but it fixed on my project. Use the latest firebase messaging and firebase core packages. It will be fixed.

Cheers! 🥳

the system can't handle notification when you remove this line

osamamohammed98 avatar May 24 '22 06:05 osamamohammed98

Hi! Sorry for taking so long to respond to your issue on GitHub. I was focused on releasing the new 0.7.0 version of awesome_notifications and awesome_notifications_fcm and i didn't had time enough to do both. But now I can answer all your questions.

So now i'm asking you to recreate this topic using the new issue template. There's a lot of missing informations that i need to understand your problem, and all the instructions are already in the new issue template. Also, remember to check beforehand if your issue was posted by another user.

So I will automatically close all previous issues so far. Sorry for the inconvenience and i will be waiting for your new issue request.

Thank you so much for your support!

rafaelsetragni avatar Sep 29 '22 17:09 rafaelsetragni