-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Comments
After adding initializeApp() with credentials from new firebase app it stopped hanging. However, now encountering:
So trying to debug this now |
with the latest firebase-ios-sdk (v10.4.0+) an APNS token is strictly required as a prerequisite to get an FCM token
|
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. |
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. 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 |
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 |
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 |
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 |
@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 |
I have been digging into this problem the whole evening. In my case the problem was that in I don't remember why did I set |
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. |
I fixed this by changing 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() |
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 However |
Hey, i just stumbled upon this issue, got a solution? |
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 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) |
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: react-native-firebase/packages/messaging/lib/index.d.ts Lines 888 to 906 in 2e51817
I'll see what I can about getting the rest of the info to actually show up on the reference site as it should. |
Hi Mike, According to the changelog there were some breaking changes:
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: |
Yes, as you quote, I quote the important bit:
That is
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" |
--> #6893 (comment) |
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 |
...across a breaking change boundary, which contains this note: https://github.com/invertase/react-native-firebase/blob/main/CHANGELOG.md#1700-2023-02-02
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. |
Yeah, but how do we actually check for the token? That's what we are asking about. How can we adjust the code? 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 |
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:
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 |
Got the same error after upgrade 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. |
This solution work for me. Thanks. I just create a firebase.json in root with the content:
Then remove the line
|
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. |
I'm having the same issue here. |
This worked well. |
Também estou nesse mesmo cenário |
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?
Thank you for your contributions. |
I'm getting this error
on ios ( using sentry ). not sure if it's related here ? |
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
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. |
I closed the emulator, used "npx expo run:ios" again, and now it works. |
I'm using the same package, but still this error happens |
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.
|
If you're winding up on this thread, and have an Expo managed project, note that there's apparently an issue under Expo v51 where it removes a necessary entitlement, you can add it back in the
See: |
For me, by changing below:
To:
Worked |
For me what solved was adding both "react-native-push-notification" and "@react-native-community/push-notification-ios" packages. Then in my entry file (root/index.js) adding this: // ... other code ...
import PushNotification from 'react-native-push-notification';
PushNotification.configure({
// Called when Token is generated (iOS and Android)
onRegister: function (token) {
console.log('TOKEN:', token);
if (Platform.OS === 'ios') {
messaging().setAPNSToken(token.token);
}
},
});
// ... other code...
AppRegistry.registerComponent(appName, () => App); |
I also suddenly got this problem, and none of the solutions in this thread helped me (I'm running on iOS simulator), a quick Erase all content and settings... solved the issue for me. 🤷 |
what version of firebase messaging & app are you using? |
This work for me, thanks |
can you please tell me what version of firebase app & messaging are you using? |
"@react-native-firebase/app": "^20.1.0", |
In my app, I'm retrieving the FCM token with the following code: try {
const granted = await messaging().requestPermission();
if (!messaging().isDeviceRegisteredForRemoteMessages) {
await messaging().registerDeviceForRemoteMessages();
}
await messaging().getToken().then(updatePushToken);
} catch (error) {
Sentry.captureException(error);
} The version of SDK is 19 It works well almost 99.9% of the time. However, sometimes Sentry captures the following error: |
@dkornilove Hi, we're using very similiar code for FCM initialization in our application and we're seeing instances of the same issue in Sentry. Right now I don't have a working fix since the issue is still under investigation, but I think for us it might either be due to using react-native-splashscreen as that was discouraged in this thread or because we're missing extra logic in the initialization code that would handle when getting the APNS token would fail (for various reasons such as to network issues). edit: I've also looked at the definition for registerDeviceForRemoteMessages - it should set the APNS token when the function successfully resolves. getAPNSToken should return the "saved" token rather than making some request. Due to having an explicit call for .registerDeviceForRemoteMessages() I'm puzzled as to how the APNS is not available at the time of calling messaging().getToken() -- although since we're using auto registration it could maybe? be possible that the auto registration has not yet completed at the time .getToken is called?? |
As has been made clear through out this thread, you need an APNS token before making FCM token required requests. If you have another issue related to messaging, please consider opening a new issue. |
Issue
Trying to get token from user.
When running this on iOS simulator, I getA
on the console but it never reaches B. On further debugging just callingawait messaging()
seems to do enough to hang.I see now after adding initializeApp() with credentials from firebase the following error
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?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
react-native-firebase
version you're using that has this issue:Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?Y
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: