Skip to content

[firebase-messaging] APNS device token not set before retrieving FCM Token for Sender ID #70

@sebj54

Description

@sebj54

Hi there,

I'm actually trying to change the @nativescript/firebase plugin for packages from this repo.

I started the "migration" with @nativescript/firebase-core and @nativescript/firebase-messaging.

When I try to register notifications with this code:

import Vue from 'nativescript-vue'
import { firebase } from '@nativescript/firebase-core'
import { AuthorizationStatus } from '@nativescript/firebase-messaging'

import Home from './components/Home'

new Vue({
    render: (h) => h('frame', [h(Home)]),
    created() {
        firebase().initializeApp()
            .then(() => {
                const messaging = firebase().messaging()

                messaging.requestPermission({
                    ios: {
                        alert: true,
                    },
                })
                    .then((authStatus) => {
                        const enabled = authStatus === AuthorizationStatus.AUTHORIZED || authStatus === AuthorizationStatus.PROVISIONAL

                        if (enabled) {
                            messaging.getToken()
                                .then((pushToken) => {
                                    console.log(pushToken)
                                    messaging.registerDeviceForRemoteMessages()
                                })

                            messaging.onMessage((message) => {
                                console.log(message)
                            })
                        }
                    })
                    .catch((error) => {
                        console.error(error)
                    })
            })
            .catch((error) => {
                console.error(error)
            })
    },
}).$start()

This error is thrown in the console (several times, starting when the promise for the permission request resolves):

8.11.0 - [Firebase/Messaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '************'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.

I don't know what I did wrong here. I think the Firebase configuration is good because it works with the same app with @nativescript/firebase.

Here is what I tried to troubleshoot (with no effect):

  • Uninstall/reinstall the app
  • Reboot the iPhone
  • Add some setTimeout before requesting permission, just to be sure everything is initialized
  • Change the order of getToken and registerDeviceForRemoteMessages
  • Check if "Push notifications" capability and needed background modes are checked in Xcode

I'm now out of solutions to fix this. Has anyone made it work with a real device?

Thanks for your help :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions