Skip to content

'No APNS token specified' error getting token on iOS #221

Description

@ebiscardi

I have an issue using this plugin on iOS. I receive this error when trying to get Firebase token:

No APNS token specified before fetching FCM Token

I put GoogleService-Info.plist and app.entitlements in app/App_Resources/iOS as described in the documentation
I tried both with xcode 14.3.1 and 15.0-beta

these are the dependencies in package.json:

@nativescript/ios: 8.5.2
@nativescript/types: 8.5.0
@nativescript/core: 8.5.5
@nativescript/firebase-core: 3.1.0
@nativescript/firebase-messaging: 3.1.0

And this is the function called when the application is started:

async function firebaseInitialization() {
    console.log("firebaseInitialization: start firebase registering");
    const defaultApp = await firebase().initializeApp();
    console.log("firebase initialized");
    console.log("request for permission");
    const enabled = await requestUserPermission()
    try {
        if (enabled) {
            firebase().messaging().showNotificationsWhenInForeground = true         
            console.log("trying to get current token")
            const token = await firebase().messaging().getToken()
            console.log("current token: " + token)
            //rest of the code
            ...
        }
    } catch (e) {
        console.log("ERROR: " + e) //<-- the error is catched here
    }
}


async function requestUserPermission() {
    const authStatus = await firebase()
        .messaging()
        .requestPermission({
            ios: {
                alert: true,
            },
        });
    const enabled = authStatus === AuthorizationStatus.AUTHORIZED || authStatus === AuthorizationStatus.PROVISIONAL;
    if (enabled) {
        console.log('Push notification authorized')
        const didRegister = await firebase().messaging()
                .registerDeviceForRemoteMessages();
        return true
    } else {
        console.log('Push notification NOT authorized')
        return false
    }
}

This is the console output:

firbaseInitialization: start firebase registering
firebase initialized
request for permission
Push notification authorized
trying to get current token
ERROR: Error: No APNS token specified before fetching FCM Token

I seem to have done everything that is requested in the documentation. Any idea?

EDIT:
I tried to wrap the registerDeviceForRemoteMessages call in a try-catch statement. No exception is thrown, but after that, the registration status, checked with firebase().messaging().isDeviceRegisteredForRemoteMessages, is false

Activity

  1. manijak commented on Jul 25, 2023

    @manijak

    Interesting. Having similar issue with FCM Messaging on iOS as well.

    My entitlements file contains the correct aps entitlement:

    <key>aps-environment</key>
    <string>development</string>
    await firebase().messaging().registerDeviceForRemoteMessages()
                .then((resolved) => {
                    console.log("FCM Register Device Result: ", resolved);
                   },(error) => {
                        console.warn("FCM Register Device ERROR: ", error);
                    });

    Keep getting error on the registerDeviceFroRemoteMessages call.
    Error in application:didFailToRegisterForRemoteNotificationsWithError: no valid “aps-environment” entitlement string found for application

    After taking a look at the .entitlements file under platforms/ios, the aps entitlement is now missing. So it seems that our custom entitlements are not being merged.

  2. wschroers commented on Jul 26, 2023

    @wschroers

    What is the name of the entitlements file located at "App_Resources\iOS"? Make sure it is "app.entitlements".
    I'm not sure but I think this might have changed were it used to be "the-name-of-the-app.entitlements" instead of just "app.entitlements".

  3. manijak commented on Jul 26, 2023

    @manijak

    Correct. I had to rename it to app.entitlements 👍 now its merging during build and the device is being registered with fcm.

  4. kefahB commented on Jul 27, 2023

    @kefahB
    Contributor

    Getting same error when updating the plugin to the latest .. I had already app.entitilments !

  5. kefahB commented on Jul 27, 2023

    @kefahB
    Contributor

    Try to accept the licence agreement changes .. make a fresh install .. that worked for me

  6. kefahB commented on Aug 1, 2023

    @kefahB
    Contributor

    it seems that you need to add this to you Info.plist :

    <key>FirebaseAppDelegateProxyEnabled</key>
        <false/>
    
  7. dlcole commented on Aug 10, 2023

    @dlcole
    Contributor

    I'm migrating my project to use the new firebase plugins and am receiving this same error message. I've included all the items listed above. This was working with the older plugin, so I have the APNS key defined in the firebase console. The specific error message is

    Error: The operation couldn’t be completed. No APNS token specified before fetching FCM Token

  8. kefahB commented on Aug 10, 2023

    @kefahB
    Contributor

    @dlcole ns clean && ns run ?? for me it was FirebaseAppDelegateProxyEnabled that fixed the issue

  9. dlcole commented on Aug 10, 2023

    @dlcole
    Contributor

    @kefahB I tried that and noticed this error:

    error: Provisioning profile "iOS Team Provisioning Profile: tech.govia.rrr" doesn't include the UIBackgroundModes entitlement. (in target 'rrr' from project 'rrr')

    I'll generate a new provisioning profile and see if that does the trick.

  10. kefahB commented on Aug 10, 2023

    @kefahB
    Contributor

    @dlcole this is another issue now, you should generate a new provision profile with the UIBackgroubdModes then install it

  11. dlcole commented on Aug 11, 2023

    @dlcole
    Contributor

    @kefahB Well, still no luck. I edited my ID to check the capabilities. I have Associated Domains and Push Notifications checked. I didn't see anything else pertinent.

    While chasing this issue I had earlier added these lines to my app.entitlesments file:

      <key>UIBackgroundModes</key>
      <array>
        <string>remote-notification</string>
      </array>
    

    I commented-out these lines, cleaned and ran, and still received the same APNS error message. Any suggestions for next steps?

  12. kefahB commented on Aug 11, 2023

    @kefahB
    Contributor

    It is a known issue on Xcode, open your project with Xcode and toggle 2 times Automatic configuration and build even if Xcode show an error msg about the profile

  13. dlcole commented on Aug 11, 2023

    @dlcole
    Contributor

    @kefahB - OK, I'm game, just trying to understand what you're suggesting. I don't see "Automatic configuration" as an option anywhere. I did toggle "Background processing" several times, built, and ran on an iOS emulator from Xcode and received the same APNS error. I'm running Xcode 14.3.

  14. dlcole commented on Aug 14, 2023

    @dlcole
    Contributor

    Upon further testing I have found that adding

        <key>FirebaseAppDelegateProxyEnabled</key>
        <false/>
    

    to info.plist is sufficient to bypass the APNS error on iOS devices, but not iOS emulators.

    BUT, I have also found that this changes causes a hang in the login process. In particular,

    let idp = await firebase().ui().show({ providers: [new PhoneProvider()] });

    yields this sequence:

    1. Welcome screen presented, with "Sign in with phone" button as only visible option - tap button
    2. Enter phone number screen presented - enter number and tap Verify
    3. Verifying you’re not a robot… screen appears briefly
    4. about:blank screen appears, empty screen with Done (upper-left) and refresh (upper-right) as only options, and tapping Done cancels the login with an error, The interaction was cancelled by the user.
    5. When I attempt to display the error message with an alert, the app crashes, even within a try/catch block
    6. When I attempt to log in again, ui().show crashed with the error message, Error: Cannot read properties of undefined (reading 'presentViewControllerAnimatedCompletion')

    Might some type of Firebase AppDelegate be required for phone authentication? I'll open a separate issue for tracking.

  15. kefahB commented on Aug 14, 2023

    @kefahB
    Contributor

    You may try to edit the delegate to set manually the apns token
    ´´´ts

    applicationDidRegisterForRemoteNotificationsWithDeviceToken(application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    fierbase().messaging().apnsToken = deviceToken; // maybe setApnsToken()
    }

    ´´´

  16. dlcole commented on Aug 14, 2023

    @dlcole
    Contributor

    @kefahB - I closed issue 231, finding that simply invoking getAPNSToken() prior to getToken() is sufficient to avoid the error documented in this issue, without having to modify info.plist. Much thanks for your help and timely responses!

  17. lano-vargas commented on Oct 5, 2023

    @lano-vargas

    Same issue here but on Simulator, Should this works on Simulator at all?

  18. dlcole commented on Oct 5, 2023

    @dlcole
    Contributor

    You'll always see this error on a simulator.

  19. lano-vargas commented on Oct 5, 2023

    @lano-vargas

    Ok... I've found out that it actually the messaging doesn't work on Simulator.

    FCM messages can be sent to real Android/iOS devices and Android emulators. iOS simulators however do not handle cloud messages.

    It state here : https://docs.nativescript.org/plugins/firebase-messaging.html#intro

  20. viren-almabay commented on Feb 8, 2024

    @viren-almabay

    This issue can occur if you are not having the provision profile you created from Apple Developer account. You need have those installed in the system you're working.

  21. lid3rs commented on Jul 11, 2024

    @lid3rs

    Guys, I need help related to this question. No matter what I do, regadless of wha i select https://developer.apple.com/account/resources/identifiers/list i just can't get rid of "Provisioning profile "xxx" doesn't include the UIBackgroundModes entitlement.". BUT, there is physically no such item "Background Modes" or alike. `i killed the entire day on this, please help! PLEASE!

    Screenshot 2024-07-11 at 22 28 11

  22. flipperlite commented on Dec 17, 2025

    @flipperlite

    Guys, I need help related to this question. No matter what I do, regadless of wha i select https://developer.apple.com/account/resources/identifiers/list i just can't get rid of "Provisioning profile "xxx" doesn't include the UIBackgroundModes entitlement.". BUT, there is physically no such item "Background Modes" or alike. `i killed the entire day on this, please help! PLEASE!

    Screenshot 2024-07-11 at 22 28 11

    From this SO question which points to the Apple docs yet disagrees if it should go into the App_Resources/iOS/app.entitlements, I put it into the App_Resources/iOS/Info.plist. Frankly, I don't see any difference in FCM notifications from UIBackgroundModes as my app worked without it but YMMV. I created a PR with some best practices for someone to comes later. I also can confirm it worked on my real device but won't work on the iOS Simulator.

        <key>UIBackgroundModes</key>
        <array>
            <string>remote-notification</string>
        </array>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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