4

I'm using flutter dependancies:

firebase_messaging: ^7.0.3
flutter_local_notifications: ^3.0.1+6

I send firebase cloud message like this:

{
"to": "/topics/demo_ios"
"notification" : {
"body" : "Hi there now now",
"title" : "Wow!",
"sound": "default"

},
 "priority": "high"
"data": {
    "title": "Hi there yes",
    "body": "Wow",
}
}

In ios the notification shows when the app is in the foreground, however when in the background it doesn't show at all. I tried reading and fixing many things, but is still doesn't work. I set background fetch, remote notificaitons, and background processing from xcode, and it still doesn't work.

I set FirebaseAppDelegateProxyEnabled to false in the plist file, but it didn't help.

I request permission:

_messaging.requestNotificationPermissions(
  const IosNotificationSettings(sound: true, badge: true, alert: true, provisional: false)
);
_messaging.onIosSettingsRegistered.listen((event) {print('2124: ios Setting registered');});
RJB
  • 1,704
  • 23
  • 50

3 Answers3

0

first I recommend you to update the plugin to firebase_messaging: ^8.0.0-dev.8, because iOS background handling is enabled there. See here this change:

  • iOS background handler support.

Next, how to integrate all of that to your flutter project, please follow official documentation FlutterFire (this is documentation just after 8.x.x-dev versions of the plugin.

Finally, please read more about APN, because Apple is handling differently those messages and you need to have the APNSConfig property inside your script for sending notifications.

If you are sending notifications via FirebaseAdmin, then please read this.

Do not forget, that in that case, you need to set content_available=True which is contained inside the APNSConfig property, so basically if you are using FirebaseAdmin you should include also property similar to this one:

apns=messaging.APNSConfig(
        payload=messaging.APNSPayload(
            aps=messaging.Aps(
                alert='alert text',
                sound='s',
                content_available=True,
                mutable_content=True,
                category='c',
                thread_id='t',
                custom_data={
                    'id': 'xxx',
                    'type': 'xxx',
                    'title': 'Robb',
                    'content': 'Axxxx',
                    'image': 'xxx',
                    'deepLink': 'xxxx',
                },
            ),
        )
    ),
Nihad Delic
  • 220
  • 2
  • 11
  • Hi, I'\m sending the notification with postman with http request, not firebase console. Do I need to use content_available = true, and apns? I didn't see anywhere about this. – RJB Dec 02 '20 at 17:56
  • I believe that the first part of my post helped you to resolve the initial question. The answer to your question regarding content_available is here https://stackoverflow.com/a/50767362/6074443 explained in detail when you should use it . – Nihad Delic Dec 02 '20 at 22:35
0

I was also having the same problem ,try to upload IPA file on testflight then it work hope so.

Parvesh Khan
  • 1,356
  • 1
  • 10
  • 9
0

Well, the solution was quite simple, and a mistake on my behalf.

As the documnents pub.dev state:

Generate the certificates required by Apple for receiving push notifications following this guide in the Firebase docs. You can skip the section titled "Create the Provisioning Profile".

Here is the link: https://firebase.google.com/docs/cloud-messaging/ios/certs

I forgot to do these steps. After doing this, it worked

RJB
  • 1,704
  • 23
  • 50