invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
465 stars 31 forks source link

[iOS] help with remote notifications #355

Closed RayVR closed 3 years ago

RayVR commented 3 years ago

Hi, I've followed the instructions for the remote notification service on iOS and setup our license files per the docs, I have also added the code necessary for the isHeadless prop injection. Android remote notifications (FCM) are working.

Questions: 1) will remote notifications, sent through FCM, trigger on a physical device with a dev build? (selecting Product -> Run with a physical device target in Xcode) 2) on a physical device running a development build, I am not able to get a token. Is this only supported in release builds? 3) What is a valid example message that should trigger a notification on iOS?

for 3 I have tried many variations of the message sent. Here are some:

// taken from notifee docs
admin.messaging().sendMulticast({tokens,
    notification: {
      title: 'A notification title!',
      body: 'A notification body',
    },
    apns: {
        payload: {
            aps: {
                'content-available': 1, // Important, to receive `onMessage` event in the foreground when message is incoming
                'mutable-content': 1, // Important, without this the extension won't fire
            },
            notifee_options: {
                image: 'https://placeimg.com/640/480/any', // URL to pointing to a remote image
                ios: {
                    sound: 'default', // A local sound file you have inside your app's bundle
                },
            },
        },
    },
})}})

admin.messaging().sendMulticast({ tokens,
                                data: {
        notifee: JSON.stringify({ body: 'This message was sent via FCM!',
                                          apns: {
                                            headers: {
                                              'apns-push-type': 'alert',
                                              'apns-priority': '10',
                                            },
                                            payload: {
                                              aps: {
                                                'content-available': 1,
                                                'mutable-content': 1,
                                                alert: {
                                                  title: 'test ios',
                                                  body: 'should display',
                                                },
                                                badge: 1,
                                                sound: 'defaut',
                                              },
                                              notifee_options: notifee_options,
                                            },
                                          },
                                android: {
                                        priority: 4,
                                        style: {
                                                type: 0,
                                                picture: 'https://placeimg.com/640/480/any'
                                        },
                                        channelId: 'msg2',
                                        actions: [ {
                                                title: 'Mark as Read',
                                                pressAction: {
                                                        id: 'read',
                                                },
                                        },],
                                },
        }),
},
})

Some simple examples of remote messages targeting iOS, sent via FCM, would be very useful in the documentation. Right now I believe most examples are for Android.

I'm not sure where to default back to the FCM vs the notifee docs on accepted fields/configuration.

helenaford commented 3 years ago

Hi @RayVR,

  1. yes
  2. no, tokens aren't handled by notifee but react-native-firebase and they work in dev
  3. the example in the code you pasted above should trigger the notification service extension to display a notification with notifee.

Hope that helps.

RayVR commented 3 years ago

I'll leave this here in case anyone else happens to have this unfortunate issue.

My firebase project for this application had a bundle ID I assigned long before the iOS app was in the app store. That bundle ID did not match the profile I created in the Apple developer console.

Creating a new project with the correct bundle ID in firebase, replacing the GoogleService-Info.plist file and rebuilding the app resolved my issues with sending notifications on iOS.

mikehardy commented 3 years ago

If I had $1 for every time I have also suffered a sort-of-self-inflicted wound like that, especially with iOS configuration....

Glad you got it sorted out!