[🐛] 🔥 getAPNSToken applies uppercase to token
Issue
We're having an issue when using the getAPNSToken function in the messaging package where the hex string returned is uppercased, but the value returned from APNS contains lowercased values.
In our project we have the following:
deviceToken = await messaging().getAPNSToken();
// The below will print an uppercase token string
console.log('APNs Token:', deviceToken);
which will print us out a device token that has all-uppercase characters. When I modify the ios AppDelegate file to log the device hex token, I see that all characters are lower case:
from the generated AppDelegate
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSUInteger length = deviceToken.length;
if (length == 0) {
return;
}
const unsigned char *buffer = (const unsigned char *)[deviceToken bytes];
NSMutableString *hexString = [NSMutableString stringWithCapacity:(length * 2)];
for (int i = 0; i < length; ++i) {
[hexString appendFormat:@"%02x", buffer[i]];
}
self.pushToken = hexString;
if (someCondition) {
[PushNotificationsHelper setPushTokenWithDeviceToken:deviceToken];
} else {
FIRMessaging.messaging.APNSToken = deviceToken;
// The below will print a lowercase token string
NSLog(@"Device token hex string is %@", hexString);
}
}
This is an issue for us since the token code is not case sensitive on the APNS-side, so if you were to send out notifications to that token as an uppercase and lowercase string the user would get that notification twice. Was there a change added that could have updated the formatting of the token?
Project Files
Javascript
Click To Expand
package.json:
# N/A
firebase.json for react-native-firebase v6:
# N/A
iOS
Click To Expand
ios/Podfile:
- [ ] I'm not using Pods
- [x] 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.settingsjetifier=truefor Android compatibility? - [ ] I am using the NPM package
jetifierfor 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
react-native info output:
System:
OS: macOS 14.6.1
CPU: (14) arm64 Apple M3 Max
Memory: 4.81 GB / 96.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.13.1
path: ~/.nvm/versions/node/v20.13.1/bin/node
Yarn:
version: 3.6.4
path: ~/.nvm/versions/node/v20.13.1/bin/yarn
npm:
version: 10.5.2
path: ~/.nvm/versions/node/v20.13.1/bin/npm
Watchman:
version: 2024.08.19.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.5
- iOS 17.5
- macOS 14.5
- tvOS 17.5
- visionOS 1.2
- watchOS 10.5
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.18034.62.2411.12071903
Xcode:
version: 15.4/15F31d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.11
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.5
wanted: ^0.74.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
- Platform that you're experiencing the issue on:
- [x] iOS
- [ ] Android
- [ ] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
react-native-firebaseversion you're using that has this issue:18.8.0
Firebasemodule(s) you're using that has the issue:messenger, app
- Are you using
TypeScript?Y&5.0.4
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
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.
Can I get an update on this? It's still an unanswered question for our team.
Hmm
https://github.com/search?q=repo%3Ainvertase%2Freact-native-firebase%20apnstoken&type=code
https://github.com/invertase/react-native-firebase/blob/9c940857a3759f85fad2f8d995b83f7c08058d6b/packages/messaging/ios/RNFBMessaging/RNFBMessagingSerializer.m#L24
I appear to have done that in a method used during the setAPNSToken call chain when I implemented token / APNS support for emulators
https://github.com/invertase/react-native-firebase/commit/8d75b36f485af07ecfa653192ca56f761d0cc5b7#diff-97d5c046fba96de49ba4b86103474a551a097bf5f8bff88fd7de30c20b0fa624R23
if they are not case sensitive on the APNS side then perhaps they should be normalized prior to your device/token mapping storage and/or de-duplicated now? Either upper or lower case appears to be valid though I'll admit it seems upper case seems more correct
Not sure how or if this should rectified at this point (people may depend on the current behavior?), but I'm open to suggestion and/or PRs (maybe a rename / deprecate of the API that does current behavior, and alter all other APNS token handling to be all upper case to match firebase-ios-sdk / iOS native APIs ? as a breaking change?)
I do think it'd be nice to get the token back in the unmodified state if possible - there definitely isn't a ton of the documentation for case sensitivity in these tokens but our team did find this that suggests we should only be sending back the token unmodified.
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.
This one is only quiet because it needs careful consideration on backwards-compatibility for a change. I think the comment indicating the token should be unmodified is as authoritative as we'll get for guidance and should be respected, just...how
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.
Commenting to keep this alive
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.
Any updates on this?
No, apologies, I must admit that when confronted with the breaking nature of the real fix for this one - including that the tokens are likely stored as data everywhere, I'm a bit frozen. There's just no good way to fix this without a big impact for people
I wonder - based on a closer look - if it is not the setAPNSToken doing it, but our NSData -> NSString transformation doing it.
I haven't investigated this specific chunk of code, but my setAPNSToken code is actually setting it to lowercase, so I can only assume that this block does a transformation that upper-cases at the same time?
https://github.com/invertase/react-native-firebase/blob/c027ef2d772882c091383b7ff81b65573f549b5d/packages/messaging/ios/RNFBMessaging/RNFBMessagingSerializer.m#L41-L50
If it does, as a temporary measure perhaps (and to show whether it does or not) you might be able to incorporate this transform in whatever other location you are looking at the token (and targeting it) to see if it results in the same token react-native-firebase is addressing?
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.