Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] The operation couldn’t be completed. No APNS token specified before fetching FCM Token #6893

Open
1 of 9 tasks
k2xl opened this issue Feb 7, 2023 · 110 comments
Open
1 of 9 tasks
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report

Comments

@k2xl
Copy link

k2xl commented Feb 7, 2023

Issue

Trying to get token from user.

import messaging from '@react-native-firebase/messaging';
import { registerRootComponent } from 'expo';
import React, { useEffect } from 'react';
import {
  Text
} from 'react-native';

async function onAppBootstrap() {
  // Register the device with FCM
  console.log('A');
  await messaging().registerDeviceForRemoteMessages();
  console.log('B');
  // Get the token
  const token = await messaging().getToken();

  // Save the token
  console.log('TOKEN ' + token);
}

function App() {
  useEffect(() => {
    onAppBootstrap();
  }, []);

  return (
    <Text>Hi</Text>
  );
}

console.log('Registering root component');
registerRootComponent(App);
export default App;

When running this on iOS simulator, I get A on the console but it never reaches B. On further debugging just calling await messaging() seems to do enough to hang.

I see now after adding initializeApp() with credentials from firebase the following error

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

Project Files

Javascript

Click To Expand

package.json:

"@react-native-firebase/app": "^17.0.0",
    "@react-native-firebase/messaging": "^17.0.0",

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

System:
OS: macOS 12.5
CPU: (10) arm64 Apple M1 Pro
Memory: 227.88 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.5.0 - /opt/homebrew/bin/node
Yarn: Not Found
npm: 9.3.1 - /opt/homebrew/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9477386
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 17.0.6 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.5 => 0.70.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • [x ] iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • `"@react-native-firebase/app": "^17.0.0",
  • "@react-native-firebase/messaging": "^17.0.0",`
    
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y


@k2xl k2xl added Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report labels Feb 7, 2023
@k2xl k2xl changed the title [🐛] await messaging().registerDeviceForRemoteMessages(); const token = await messaging().getToken(); [🐛] await messaging() hangs Feb 7, 2023
@k2xl
Copy link
Author

k2xl commented Feb 7, 2023

After adding initializeApp() with credentials from new firebase app it stopped hanging. However, now encountering:

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

So trying to debug this now

@k2xl k2xl changed the title [🐛] await messaging() hangs [🐛] The operation couldn’t be completed. No APNS token specified before fetching FCM Token Feb 7, 2023
@mikehardy
Copy link
Collaborator

with the latest firebase-ios-sdk (v10.4.0+) an APNS token is strictly required as a prerequisite to get an FCM token
The SDKs try to handle this for you by swizzling in AppDelegate methods that register an APNS token if one comes, but if you disable swizzling, or you do not register for remote notifications prior to calling getToken, you'll never get one

  • do not disable swizzling
  • make sure you call registerForRemoteNotifications

@k2xl
Copy link
Author

k2xl commented Feb 7, 2023

Hi @mikehardy thanks for the response. I'm very confused. Apologies as I'm still relatively new to react-native. Note that I'm also using Expo.

In my example above, I am calling registerForRemoteNotifications before calling getToken.

@mikehardy
Copy link
Collaborator

I'm not sure why, but the FCM system does not have an APNS token set for your app before you request an FCM token.
There can be a few reasons why, as mentioned above it could be that swizzling is disabled in your AppDelegate such that the FCM callback which would normally listen for / register the APNS token with FCM when it comes in is not hooked up. It could be that you do not have remote messaging set up as an entitlement for your app. It could be lots of things.

One thing that might be uncomfortable to hear but is nevertheless important: others have this working. The code works in the module. Why is that important but maybe uncomfortable? Because it implies (though no, it does not quite prove...) that the problem is specific to your app and your configuration. You should triple check everything with the assumption the problem is in your app and no one will be able to help you find it - you will likely find the problem yourself in your app upon further careful inspection.

There is still of course the possibility the problem is in this module, but no one else is experiencing it so I am operating on the assumption the problem is project-specific

@k2xl
Copy link
Author

k2xl commented Feb 8, 2023

Thank you for your respectful response! Definitely appreciate this input.

I think part of the reason I raised this issue is that I did see some other threads for a few weeks ago related to this issue. So I thought just getting the minimal example to reproduce the issue could cause an issue - so in case anyone else encounters and has found a solution they may stumble upon this ticket.

The fact that this sounds like only affecting me indicates it is indeed a problem with my configuration - I guess the tough part I'll need to figure out is what is the issue with my configuration:).

Anyway best regards, and thanks again for the pointers

@mikehardy
Copy link
Collaborator

The new strict requirement for an APNS token prior to an FCM one is bound to turn up issues like this so I will be very curious to hear what you turn up. Right now the entitlements idea is my best one for you but maybe it's something else? There was a lot of traffic about this recently because they added this requirement first on the backend without warning which exposed lots of people getting FCM tokens with no corresponding APNS token and broke their apps.

Of course those non-APNS FCM tokens are useless, but breaking the misconfigured apps unexpectedly was bad and generated all the traffic. They relaxed the backend change but left the SDK change in for firebase-ios-sdk 10.4.0 release so it is now only seen by folks as they upgrade, which is you now. It's a valid change (the APNS token should be required...) but forces everyone to find their corner cases where it fails now. And here we are...

Anyway, definitely report back if you find anything, and I hope you do + quickly. Cheers

@nicolasburtey
Copy link

nicolasburtey commented Feb 8, 2023

also running into this issue today. not sure right now why that is.

it's not a minimal example, but issue can be seen by cloning this repo: https://github.com/GaloyMoney/galoy-mobile

@farojos
Copy link

farojos commented Feb 9, 2023

@k2xl I had the same issue minutes before.

I solved it by checking in signing & capabilities. Inside "Background modes", I selected "Background check" and "Remote notifications". I hope this helps you.

@nicolasburtey
Copy link

@k2xl I had the same issue minutes before.

I solved it by checking in signing & capabilities. Inside "Background modes", I selected "Background check" and "Remote notifications". I hope this helps you.

just tried that and had no effect on my end.

I realized I had not set use_frameworks! :linkage => :static in the Podfile even thought it was necessary from a recent update, but it doesn't seem to remove the error message.

@tautvilas
Copy link

I have been digging into this problem the whole evening. In my case the problem was that in firebase.json property registerDeviceForRemoteMessages was set to false. This caused getAPNSToken to return null and also triggered this error in case getToken was called.

I don't remember why did I set registerDeviceForRemoteMessages to false earlier before. But this still looks like firebase bug. Because I did call registerDeviceForRemoteMessages in my JS code, but for some reason that did not perform the registration fully. One interesting behaviour that I noticed was that APNSToken was not not null only in the case when app was launched first time after install (with registerDeviceForRemoteMessages=false setup) .

@nicolasburtey
Copy link

on my end, solving by doing a full re-install off the app. don't know how it got corrupted in the first place but anyway, no longer seen the error message.

@kesha-antonov
Copy link

I fixed this by changing firebase.json

From

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": false
  }
}

To

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": true
  }
}

And deleted call

await messaging().registerDeviceForRemoteMessages()

@k2xl
Copy link
Author

k2xl commented Feb 13, 2023

Thanks for the responses. I am on an expo managed app so didn't have a firebase.json file...

I tried adding a firebase.json to the root of the folder and removed the await messaging().registerDeviceForRemoteMessages() (since it was showing that it was unneeded).

However
await messaging().getToken();
hangs... and I still get The operation couldn’t be completed. No APNS token specified before fetching FCM Token

@Spxc
Copy link

Spxc commented Feb 16, 2023

Thanks for the responses. I am on an expo managed app so didn't have a firebase.json file...

I tried adding a firebase.json to the root of the folder and removed the await messaging().registerDeviceForRemoteMessages() (since it was showing that it was unneeded).

However await messaging().getToken(); hangs... and I still get The operation couldn’t be completed. No APNS token specified before fetching FCM Token

Hey, i just stumbled upon this issue, got a solution?
According to the docs setAPNS needs to be called, just not sure how or where

@mikehardy
Copy link
Collaborator

According to the docs setAPNS needs to be called,

I don't believe this statement is true? The docs should say (and I think they say?) that you must call setAPNS *if you have disabled method swizzling or for some other reason have disabled the automatic firebase APNS token handling on remote message registration

In almost all cases, certainly the "default integration" cases, if you call the API to register for remote notifications, and have @react-native-firebase/messaging installed in the default manner with correct entitlements on your iOS project to allow them, the SDK will request an APNS token from Apple and set it into the SDK for you fully automated.

You only want or need to use setAPNS token if you really want to manage APNS tokens yourself (for automated testing on non-Apple-Silicon emulators, perhaps, or if you have some brownfield app where you manage APNS tokens yourself, etc)

@mikehardy
Copy link
Collaborator

We appear to have an issue in the reference API docs where line breaks in our method docs stop the rest of the doc from rendering but the whole doc is as such:

/**
* On iOS, This method is used to set the APNs Token received by the application delegate.
* Note that the token is expected to be a hexadecimal string, as it is an NSData type in
* the underlying native firebase SDK, and raw data may only be passed as a string if it is
* hex encoded. Calling code is responsible for correct encoding, you should verify by comparing
* the results of `getAPNSToken()` with your token parameter to make sure they are equivalent
*
* Messaging uses method swizzling to ensure that the APNs token is set automatically.
* However, if you have disabled swizzling by setting FirebaseAppDelegateProxyEnabled to NO
* in your app’s Info.plist, you should manually set the APNs token in your application
* delegate’s application(_:didRegisterForRemoteNotificationsWithDeviceToken:) method.
*
* If you would like to set the type of the APNs token, rather than relying on automatic
* detection, provide a type of either 'prod', 'sandbox'. Omitting the type parameter
* or specifying 'unknown' will rely on automatic type detection based on provisioning profile.
*
* At a native level you may also call objective-c `[FIRMessaging setAPNSToken];` as needed
*
* > You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve `null`.

I'll see what I can about getting the rest of the info to actually show up on the reference site as it should.

@Spxc
Copy link

Spxc commented Feb 16, 2023

According to the docs setAPNS needs to be called,

I don't believe this statement is true? The docs should say (and I think they say?) that you must call setAPNS *if you have disabled method swizzling or for some other reason have disabled the automatic firebase APNS token handling on remote message registration

In almost all cases, certainly the "default integration" cases, if you call the API to register for remote notifications, and have @react-native-firebase/messaging installed in the default manner with correct entitlements on your iOS project to allow them, the SDK will request an APNS token from Apple and set it into the SDK for you fully automated.

You only want or need to use setAPNS token if you really want to manage APNS tokens yourself (for automated testing on non-Apple-Silicon emulators, perhaps, or if you have some brownfield app where you manage APNS tokens yourself, etc)

Hi Mike,
Thanks for the reply!

According to the changelog there were some breaking changes:

[17.0.0](2023-02-02)
⚠ BREAKING CHANGES
app, ios: You must have an APNS token before calling getToken to get an FCM token on iOS. Previously it was not required. See documentation for setAPNSToken if you are using getToken in testing or have disabled FCM Swizzling, and use setAPNSToken to set a token before using getToken

EDIT: Saw your reply, i'll have a read through. The thing is, nothing changed in our code, we just updated the package, then it started throwing the APNS error. Been working flawlessly prior to this :)

How i noticed it; the entire app hung on the splash screen (both simulator and device - iOS). Moving the getToken() function to after the app checks for permissions, fixed the freeze. However it's throwing the error:
Failed to fetch FCM: Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token

@mikehardy
Copy link
Collaborator

Yes, as you quote, I quote the important bit:

See documentation for setAPNSToken if you are using getToken in testing or have disabled FCM Swizzling

That is

if you are using getToken in testing or have disabled FCM Swizzling

Almost no one does either. In the testing case, you can inject a "correctly formatted but useless" APNS token just to exercise FCM APIs, but who would do that except someone that implements FCM APIs (that is: us here, as maintainers...). So it's possible but I expect no one else to do it.

And disabling swizzling is something I'd consider "advanced" on the iOS side. If you're disabling swizzling you are effectively on your own as you have moved past the default + works implementation and are stating clearly (by disabling swizzling): "we know what we're doing on iOS, don't worry about us"

@mikehardy
Copy link
Collaborator

EDIT: Saw your reply, i'll have a read through. The thing is, nothing changed in our code, we just updated the package, then it started throwing the APNS error. Been working flawlessly prior to this :)

--> #6893 (comment)

@Spxc
Copy link

Spxc commented Feb 16, 2023

Yes, as you quote, I quote the important bit:

See documentation for setAPNSToken if you are using getToken in testing or have disabled FCM Swizzling

That is

if you are using getToken in testing or have disabled FCM Swizzling

Almost no one does either. In the testing case, you can inject a "correctly formatted but useless" APNS token just to exercise FCM APIs, but who would do that except someone that implements FCM APIs (that is: us here, as maintainers...). So it's possible but I expect no one else to do it.

And disabling swizzling is something I'd consider "advanced" on the iOS side. If you're disabling swizzling you are effectively on your own as you have moved past the default + works implementation and are stating clearly (by disabling swizzling): "we know what we're doing on iOS, don't worry about us"

Yeah, but the thing is; this code have been running fine in a simulator upon until today when doing a package update, then the freeze, now the error. This also occurred on a real device

@mikehardy
Copy link
Collaborator

when doing a package update

...across a breaking change boundary, which contains this note:

https://github.com/invertase/react-native-firebase/blob/main/CHANGELOG.md#1700-2023-02-02

app, ios: You must have an APNS token before calling getToken to get an FCM token on iOS. Previously it was not required. See documentation for setAPNSToken if you are using getToken in testing or have disabled FCM Swizzling, and use setAPNSToken to set a token before using getToken

It's a big deal, it must be handled.

Getting an APNS token is an asynchronous network-bound process that could fail, or may even be disabled by some configuration issue.

Previously these misconfigurations or order-of-operations issues were ignored and Firebase would gladly vend an FCM token that was useless as it had no corresponding APNS counterpart.

Now it is (correctly, but maybe painfully) saying "Nope, an FCM token in this context is actually without value, so we won't give you an FCM token without the APNS token behind it"

And we all have to adjust by making sure the APNS token is really there before asking for an FCM token. Might require checking network, re-trying, verifying you really register for remote notifications, you really have your iOS app entitlements correct, you have permission etc, but that's all justified and correct. Just a bit painful, maybe unexpected.

@Spxc
Copy link

Spxc commented Feb 16, 2023

Yeah, but how do we actually check for the token? That's what we are asking about. How can we adjust the code?
We've followed the docs step by step, and it's this simple line:
firebase.messaging().getToken()

Isn't that function supposed to check to see if the APNS are there?

Just want to reiterate: that all the certificates/keys etc are in order

@mikehardy
Copy link
Collaborator

Isn't that function supposed to check to see if the APNS are there?

well...it does, but not in a pleasant way. It checks and throws an error if it's not there. Shouldn't be hanging you should be getting the error I think you report:

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

So, perhaps you want to make sure you have permissions from the user, that you register for remote notifications, and that getAPNSToken returns a token (any token, value doesn't matter - except undefined is bad of course). Once those work (perhaps in a backoff retry loop with a final error to user saying some functionality won't work?) then you go for the FCM token

@Spxc
Copy link

Spxc commented Feb 16, 2023

So, perhaps you want to make sure you have permissions from the user, that you register for remote notifications, and that getAPNSToken returns a token (any token, value doesn't matter - except undefined is bad of course). Once those work (perhaps in a backoff retry loop with a final error to user saying some functionality won't work?) then you go for the FCM token

Awesome, yes, that's exactly what I ended up doing.

Good to know that it handles the error kinda weird. The hanging/freezing issue was fixed by moving the getToken() function after requesting permissions from the user.

@flashman2
Copy link

Got the same error after upgrade
"@react-native-firebase/messaging": "^14.7.0" -> "@react-native-firebase/messaging": "^17.3.0"
Only iOS issue, on Android seems everything is fine.

Signing & Capabilities -> Background Modes (Remote notifications, Background processing) enabled.

Before this upgrade everything was fine. Is there any solution for this issue?

I see this is a new issue but I think a lot of people will see this issue after upgrades. So any workaround, patch or instruction is really needed. Right now, I decided to stick with old version of module.

@rhfksl
Copy link

rhfksl commented Oct 5, 2023

  1. didRegisterForRemoteNotificationsWithDeviceToken

Hi please where do I add or find this "didRegisterForRemoteNotificationsWithDeviceToken"

I setup "didRegisterForRemoteNotificationsWithDeviceToken" when I install @react-native-community/push-notification-ios

// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [FIRMessaging messaging].APNSToken = deviceToken;
 [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

@samih-dev
Copy link

samih-dev commented Oct 8, 2023

Rodney-Web + rhfksl method worked for me,
for those whom don't use @react-native-community/push-notification-ios, just comment OUT the code related:
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];

@gerardcastell
Copy link

gerardcastell commented Oct 17, 2023

For me, the key was in this sentence:

Getting an APNS token is an asynchronous network-bound process that could fail, or may even be disabled by some configuration issue.
Adding a delay worked, nevertheless, I worked until a month ago. Do not know why this process takes much more time now.
The code to make it work is the following:

    const delay = ms => new Promise(res => setTimeout(res, ms));
    await delay(1000);
    return await messaging().getToken();

Thanks @mikehardy !

@kg-currenxie
Copy link

kg-currenxie commented Oct 25, 2023

I'm curious why registerDeviceForRemoteMessages() promise won't give us back the tokens immediately? Most promises return a value/status etc..

Which apps would call registerDeviceForRemoteMessages but NOT get the tokens? Probably none 🤔 So let the library do that work instead..

Proposal:

registerDeviceForRemoteMessages.then(function({ fcmToken, apnsToken }) {
  console.log(fcmToken, apnsToken)
})

// or
const { fcmToken, apnsToken } = await registerDeviceForRemoteMessages()

This would eliminate all these issue with getToken/getAPNSToken.

@mikehardy
Copy link
Collaborator

It could hang indefinitely if network is down

@ealimardaniii
Copy link

ealimardaniii commented Nov 14, 2023

You should first call getAPNSToken method and after that call setAPNSToken method

      await messaging().registerDeviceForRemoteMessages();
      const apnsToken = await messaging().getAPNSToken();
      if (apnsToken) {
        await messaging().setAPNSToken(apnsToken);
      }
     fcmToken = await messaging().getToken();

@savio777
Copy link

I got sorted it out by adding the <key>FirebaseAppDelegateProxyEnabled</key> <true /> property in info.plist file.

this and

I fixed this by changing firebase.json

From

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": false
  }
}

To

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": true
  }
}

And deleted call

await messaging().registerDeviceForRemoteMessages()

work for me :)
my configs:

    "react": "18.2.0",
    "react-native": "0.72.6",
    "@react-native-firebase/analytics": "^18.4.0",
    "@react-native-firebase/app": "^18.4.0",
    "@react-native-firebase/messaging": "^18.4.0",

@mronline
Copy link

mronline commented Dec 6, 2023

I noticed something interesting. Could this be the cause of the problem?

While I was looking for an error I encountered on Android (onNotificationOpenedApp is not working on Android): I came across this comment by @mikehardy: crazycodeboy/react-native-splash-screen#289 (comment)

When I comment this line in AppDelegate.mm:
[RNSplashScreen show];

The token comes, but if I remove the comment I get the error: "No APNS token specified before fetching FCM Token".

messaging().requestPermission().then(async (authorizationStatus) => {
    try {
        const fcmToken = await messaging().getToken();
        Alert.alert('fcmToken', fcmToken);
    } catch (e) {
        Alert.alert('fcmToken', e.message);
    }
});

@mikehardy
Copy link
Collaborator

That module is not recommended. No one should use it. I am shocked people still are.

React-native-bootsplash

@mronline
Copy link

mronline commented Dec 6, 2023

After reading your comment, I immediately switched to React-native-bootsplash. Currently, I do not receive this error: "No APNS token specified before fetching FCM Token". Thank you.

@mikehardy
Copy link
Collaborator

@mronline another developer saved 😆 . Happy that helped

@huydosgtech
Copy link

huydosgtech commented Jan 2, 2024

I solved by adding this code into AppDelegate.mm file.
You can try this solution.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [FIRMessaging messaging].APNSToken = deviceToken; //add this line }

@hussainarthuna
Copy link

I got the same error but after adding the below function it fixed my issue and now I can get the Token.

async registerAppWithFCM(): Promise<void> { await messaging().registerDeviceForRemoteMessages(); }

@Maksim-creator
Copy link

I got sorted it out by adding the <key>FirebaseAppDelegateProxyEnabled</key> <true /> property in info.plist file.

works for me

@mohamedabkal
Copy link

For me the issue was happening on ios because i didn't setup the Push Notifications capability correctly in App Store Connect.
I followed this guide and it helped me a lot https://medium.com/@ashoniaa/react-native-expo-push-notifications-with-fcm-a-step-by-step-guide-fa5cfc0372fd

@EduardoBravoP
Copy link

After reading your comment, I immediately switched to React-native-bootsplash. Currently, I do not receive this error: "No APNS token specified before fetching FCM Token". Thank you.

This worked for me too, thank you!

@DiegoDelBianco
Copy link

I fixed this by changing firebase.json

From

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": false
  }
}

To

{
  "react-native": {
    "analytics_auto_collection_enabled": false,
    "messaging_auto_init_enabled": false,
    "messaging_ios_auto_register_for_remote_messages": true
  }
}

And deleted call

await messaging().registerDeviceForRemoteMessages()

This solution work for me. Thanks.

I just create a firebase.json in root with the content:

{
"react-native": {
"messaging_ios_auto_register_for_remote_messages": true
}
}

Then remove the line

await messaging().registerDeviceForRemoteMessages()

@ademirtemur
Copy link

ademirtemur commented Mar 2, 2024

i think, it is your xcode version, if you use xcode 15.2 or highest xcode. you can try after upgrade the mobile device's software(OS) version. Install software(OS) updates on the device.

@Klyado
Copy link

Klyado commented Mar 8, 2024

I'm having the same issue here.
@ademirtemur Could you please give more details? Not sure to understand your solution.

@DarrKing
Copy link

100% Fixed my issue by:

  1. setting FirebaseAppDelegateProxyEnabled to NO in Info.plist
  2. Go to AppDelegate.mm and add the following inside didFinishLaunchingWithOptions function:
    [application registerForRemoteNotifications];
  3. Go to didRegisterForRemoteNotificationsWithDeviceToken function and add this:
    [FIRMessaging messaging].APNSToken = deviceToken;
  4. Clean build and start build again.

(FYI, make sure to use real device for testing.)

Hope it works for you guys.

FYI: If you are using Firebase dynamic links for your project you can just switch the FirebaseAppDelegateProxyEnabled to YES as it causes issues with dynamic links.

This worked well.

@FabricioAllves
Copy link

Obrigado pelas respostas. Estou em um aplicativo gerenciado pela Expo, então não tinha um arquivo firebase.json...

Tentei adicionar um firebase.json na raiz da pasta e removi await messaging().registerDeviceForRemoteMessages()(pois estava mostrando que era desnecessário).

No entanto await messaging().getToken(); trava... e ainda consigoThe operation couldn’t be completed. No APNS token specified before fetching FCM Token

Também estou nesse mesmo cenário

Copy link

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Apr 18, 2024
@a-eid
Copy link

a-eid commented Apr 26, 2024

I'm getting this error

Error: [messaging/unknown] The data couldn’t be read because it isn’t in the correct format.

on ios ( using sentry ).

not sure if it's related here ?

@github-actions github-actions bot removed the Type: Stale Issue has become stale - automatically added by Stale bot label Apr 26, 2024
@tristanheilman
Copy link

tristanheilman commented May 15, 2024

Not sure if this provides any insights. I've been working with language translation on my react native app and have found that whenever I change the preferred/set language of my iOS device and open my RN app, the messaging().getToken() FCM token fetch fails with this error code:

[Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token]

The issue tends to resolve itself by attempting to restart the app a few times. Are there any specifics to why this would occur? Does modifying device settings invalidate an APNS token? Very confused why switching from English -> Spanish would cause this reproducible bug so easily.

@Jiroge
Copy link

Jiroge commented May 20, 2024

I closed the emulator, used "npx expo run:ios" again, and now it works.
I think this will help.

@yuriiburov
Copy link

After reading your comment, I immediately switched to React-native-bootsplash. Currently, I do not receive this error: "No APNS token specified before fetching FCM Token". Thank you.

I'm using the same package, but still this error happens

@mhassanmalik
Copy link

My issue was resolved by adding onRegister() inside PushNotification.configure(). I was not setting the retrieved APNS token in messaging() before asking for the FCM token.

onRegister(token) {
  if (Platform.OS === 'ios') {
    messaging().setAPNSToken(token.token);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report
Projects
None yet
Development

No branches or pull requests