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

[🐛] 🔥 getAPNSToken applies uppercase to token #8022

Open
2 of 10 tasks
dan-peluso opened this issue Sep 17, 2024 · 4 comments
Open
2 of 10 tasks

[🐛] 🔥 getAPNSToken applies uppercase to token #8022

dan-peluso opened this issue Sep 17, 2024 · 4 comments
Labels
Needs Attention platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report

Comments

@dan-peluso
Copy link

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
  • 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

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:
    • iOS
    • Android
    • 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:
    • 18.8.0
  • Firebase module(s) you're using that has the issue:
    • messenger, app
  • Are you using TypeScript?
    • Y & 5.0.4


@dan-peluso dan-peluso changed the title 🔥 [🐛] Bug Report Title - getAPNSToken applies uppercase to token [🐛] 🔥 Bug Report Title - getAPNSToken applies uppercase to token Sep 17, 2024
@dan-peluso dan-peluso changed the title [🐛] 🔥 Bug Report Title - getAPNSToken applies uppercase to token [🐛] 🔥 getAPNSToken applies uppercase to token Sep 17, 2024
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 Stale label Oct 15, 2024
@dan-peluso
Copy link
Author

Can I get an update on this? It's still an unanswered question for our team.

@github-actions github-actions bot removed the Stale label Oct 15, 2024
@mikehardy
Copy link
Collaborator

Hmm

https://github.com/search?q=repo%3Ainvertase%2Freact-native-firebase%20apnstoken&type=code

I appear to have done that in a method used during the setAPNSToken call chain when I implemented token / APNS support for emulators

8d75b36#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?)

@dan-peluso
Copy link
Author

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.

@russellwheatley russellwheatley added platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention platform: ios plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report
Projects
None yet
Development

No branches or pull requests

3 participants