invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.69k stars 2.21k forks source link

[🐛] [messaging/unregistered] after messaging().registerDeviceForRemoteMessages() on iOS 16.2 #6829

Closed antonandreyev closed 8 months ago

antonandreyev commented 1 year ago

Issue

After messaging().registerDeviceForRemoteMessages() use of messaging().getToken() is still throwing [messaging/unregistered] You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages() on iOS 16.2. Probably some older or newer versions are also affected, but not visible in my logs at the moment. If more logs will come I will update the issue.

Code is simple:

messaging()
  .registerDeviceForRemoteMessages() // no-op on Android and if already registered
  .then(() => messaging().getToken())
  .then((t) => {
    setToken(t);
    setIsInitialized(true);
  }) 

UPD:

To clarify about my case: that didn't came overnight. We started to notice this "need to register" error a while ago. We thought we could fix that with explicitly registering and changed code to that is in the opening message. But that didn't help and now we see both "no need to register" and "you need to register". The case is quite rare though.

Using Sentry, here are some extractions from logs:

UPD: Sentry statistics for 48 hours:

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "...", "version": "0.1.0", "license": "UNLICENSED", "main": "index.js", "private": true, "engineStrict": true, "engines": { "node": "16.19.0", "yarn": "1.22.17" }, "scripts": { "ios": "react-native run-ios", "web": "expo start --web", "start": "react-native start --reset-cache", "start-cached": "react-native start", "lint": "eslint . --ext .tsx,.ts", "lint:fix": "yarn lint --fix", "tsc": "tsc", "test": "jest", "test:ci": "jest --passWithNoTests --ci", "codegen": "graphql-codegen", "translation:gen": "ts-node scripts/fetch-static-translations.ts && prettier --write src/__resources__/i18n_resource.json", "prettier": "prettier --check './src/**/*.{ts,tsx,json}'", "prettier:fix": "prettier --write './**/*.{ts,tsx,json}'", "prepare": "husky install", "ci": "rm -rf node_modules && yarn install --prefer-offline --frozen-lockfile && yarn cache clean", "postinstall": "patch-package", "ios:test": "yarn detox test --configuration ios.debug", "ios:build": "yarn detox build --configuration ios.debug", "e2e:ios": "yarn ios:build && yarn ios:test", "android:test": "yarn detox test --configuration android", "android:build": "yarn detox build --configuration android", "e2e:android": "yarn android:build && yarn android:test" }, "dependencies": { "@apollo/client": "^3.7.3", "@formatjs/intl-getcanonicallocales": "^2.0.5", "@formatjs/intl-locale": "^3.0.11", "@formatjs/intl-numberformat": "^8.3.3", "@formatjs/intl-pluralrules": "^5.1.8", "@gorhom/bottom-sheet": "~4.4.5", "@react-native-async-storage/async-storage": "~1.17.11", "@react-native-clipboard/clipboard": "^1.11.1", "@react-native-community/art": "^1.2.0", "@react-native-firebase/analytics": "^16.4.6", "@react-native-firebase/app": "~16.4.6", "@react-native-firebase/messaging": "^16.4.6", "@react-native-masked-view/masked-view": "^0.2.8", "@react-navigation/bottom-tabs": "6.5.0", "@react-navigation/native": "6.1.0", "@react-navigation/stack": "6.3.8", "@sentry/react-native": "4.2.2", "accordion-collapse-react-native": "^1.1.1", "d3-scale": "^4.0.2", "date-fns": "^2.29.3", "date-fns-tz": "^1.3.7", "expo": "~46.0.17", "expo-av": "~12.0.4", "expo-constants": "~13.2.4", "expo-device": "~4.3.0", "expo-file-system": "~14.1.0", "expo-font": "~10.2.0", "expo-network": "~4.3.0", "expo-secure-store": "~11.3.0", "expo-splash-screen": "~0.16.2", "expo-updates": "~0.14.7", "expo-web-browser": "~11.0.0", "formik": "^2.2.9", "graphql": "^16.6.0", "i18next": "^22.4.9", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", "lottie-react-native": "~5.1.3", "luxon": "^3.2.1", "react": "18.0.0", "react-apollo-network-status": "^5.2.1", "react-dom": "18.0.0", "react-i18next": "^12.1.4", "react-native": "0.69.7", "react-native-animatable": "^1.3.3", "react-native-calendars": "^1.1293.0", "react-native-device-info": "^10.3.0", "react-native-gesture-handler": "^2.8.0", "react-native-indicators": "^0.17.0", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-linear-gradient": "^2.6.2", "react-native-localize": "^2.2.4", "react-native-media-query": "^2.0.0", "react-native-reanimated": "~2.13.0", "react-native-safe-area-context": "^4.4.1", "react-native-screens": "^3.18.2", "react-native-share": "^8.0.0", "react-native-skeleton-placeholder": "5.2.4", "react-native-svg": "^13.6.0", "react-native-url-polyfill": "^1.3.0", "react-native-view-pdf": "^0.14.0", "sentry-expo": "^5.0.3", "styled-components": "~5.3.6", "victory-core": "~36.6.8", "victory-native": "~36.6.8", "victory-tooltip": "~36.6.8", "yup": "^0.32.11", "zod": "^3.20.2" }, "devDependencies": { "@babel/core": "~7.20.12", "@babel/plugin-syntax-flow": "^7.18.6", "@babel/plugin-transform-react-jsx": "^7.20.7", "@babel/preset-typescript": "~7.18.6", "@expo/config": "^7.0.3", "@graphql-codegen/cli": "^2.16.3", "@graphql-codegen/near-operation-file-preset": "^2.5.0", "@graphql-codegen/schema-ast": "^2.6.1", "@graphql-codegen/typescript-operations": "^2.5.12", "@graphql-codegen/typescript-react-apollo": "~3.3.7", "@testing-library/react-native": "^10.1.1", "@tsconfig/node16": "^1.0.3", "@types/d3-scale": "^4.0.3", "@types/jest": "^27.5.2", "@types/luxon": "^3.2.0", "@types/node": "^17.0.45", "@types/react": "~18.0.26", "@types/react-native": "~0.69.16", "@types/xml2js": "^0.4.11", "@typescript-eslint/eslint-plugin": "^5.48.1", "@typescript-eslint/parser": "^5.48.1", "@xtrctio/eslint-plugin-disallow-date": "^1.0.1", "babel-preset-expo": "^9.2.2", "cross-fetch": "^3.1.5", "detox": "^20.1.1", "eslint": "^8.31.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.6.0", "eslint-config-react-app": "^7.0.1", "eslint-loader": "^4.0.2", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsx-a11y": "^6.7.0", "eslint-plugin-react": "^7.31.11", "eslint-plugin-react-hooks": "^4.3.0", "expo-cli": "^6.0.8", "graphql-tag": "^2.12.6", "husky": "^8.0.3", "import-sort-style-eslint": "^6.0.0", "jest": "27.5.1", "jest-junit": "^15.0.0", "lint-staged": "^13.1.0", "patch-package": "^6.5.1", "prettier": "2.8.2", "prettier-plugin-import-sort": "^0.0.7", "react-native-dotenv": "^3.4.6", "react-test-renderer": "18.0.0", "ts-node": "^10.9.1", "typescript": "~4.9.4" }, "importSort": { ".js, .jsx, .ts, .tsx": { "style": "eslint", "parser": "typescript" } }, "lint-staged": { "**/*.ts?(x)": [ "eslint", "prettier --write" ] } } ``` #### `firebase.json` for react-native-firebase v6: (no firebase.json) ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking") require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods") require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules") platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false production = ENV["PRODUCTION"] == "1" require 'json' podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {} target '...' do use_expo_modules! post_integrate do |installer| begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end end config = use_native_modules! config = use_frameworks! :linkage => :static # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config["reactNativePath"], :hermes_enabled => podfile_properties['expo.jsEngine'] == 'hermes', :production => production, :fabric_enabled => flags[:fabric_enabled], # disable due to use_frameworks needed by firebase :flipper_configuration => FlipperConfiguration.disabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) pod 'Firebase/Analytics' post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import #import #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTAppSetupPrepareApp(application); [FIRApp configure]; RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions]; NSDictionary *initProps = [self prepareInitialProps]; UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil]; if (@available(iOS 13.0, *)) { rootView.backgroundColor = [UIColor systemBackgroundColor]; } else { rootView.backgroundColor = [UIColor whiteColor]; } self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [self.reactDelegate createRootViewController]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [super application:application didFinishLaunchingWithOptions:launchOptions]; return YES; } - (NSDictionary *)prepareInitialProps { NSMutableDictionary *initProps = [NSMutableDictionary new]; return initProps; } - (NSArray> *)extraModulesForBridge:(RCTBridge *)bridge { // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here! return @[]; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #ifdef DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } // Linking API - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options]; } // Universal Links - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { return [super application:application didFailToRegisterForRemoteNotificationsWithError:error]; } // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } @end ```


Android

Click To Expand

N/A


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: Windows 10 10.0.22621 CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H Memory: 9.29 GB / 31.68 GB Binaries: Node: 16.19.0 - C:\Users\ANTON~1.AND\AppData\Local\Temp\yarn--1673424499379-0.7430549663942487\node.CMD Yarn: 1.22.17 - C:\Users\ANTON~1.AND\AppData\Local\Temp\yarn--1673424499379-0.7430549663942487\yarn.CMD npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 27, 30, 31, 33 Build Tools: 27.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0 System Images: android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64 Android NDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: Not Found Languages: Java: 11.0.15 npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.7 => 0.69.7 react-native-windows: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **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-firebase` version you're using that has this issue:** - `16.4.6` - **`Firebase` module(s) you're using that has the issue:** - `messaging` - **Are you using `TypeScript`?** - `Y` & `4.9.4`


michalpawlowski34 commented 1 year ago

https://rnfirebase.io/messaging/usage/ios-setup Seems like there are some additional configurations needed for iOS. Since I haven't enrolled for the developer program yet, I can not tell if this can fix the issue. Have anyone tried going through the process? If not, I'll be able to test in a few days.

Edit: I also found that some of the info is bit outdated, so instead of searching for "Push notifications" capability, you should select "Background Modes" and then check "Background fetch" and "Remote notifications" image

I have this configuration applied, the docs are updated tho - unfortunatelly I'm still getting the same error.

arqummalik1 commented 1 year ago

https://rnfirebase.io/messaging/usage/ios-setup Seems like there are some additional configurations needed for iOS. Since I haven't enrolled for the developer program yet, I can not tell if this can fix the issue. Have anyone tried going through the process? If not, I'll be able to test in a few days. Edit: I also found that some of the info is bit outdated, so instead of searching for "Push notifications" capability, you should select "Background Modes" and then check "Background fetch" and "Remote notifications" image

I have this configuration applied, the docs are updated tho - unfortunatelly I'm still getting the same error.

i have resolved the issue just by going through docs , enabling Background Fetch. and Remote Notifications also Enabling Push Notifications in the Xcode-> Target-> Capabilities-> Push Notifications. Then Close the xcode and re-run the build .Hopefully it should resolve the issue. Thank you

github-actions[bot] commented 1 year ago

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.

hamzakashifCL commented 1 year ago

https://rnfirebase.io/messaging/usage/ios-setup Seems like there are some additional configurations needed for iOS. Since I haven't enrolled for the developer program yet, I can not tell if this can fix the issue. Have anyone tried going through the process? If not, I'll be able to test in a few days.

Edit: I also found that some of the info is bit outdated, so instead of searching for "Push notifications" capability, you should select "Background Modes" and then check "Background fetch" and "Remote notifications" image

Still getting the error even after applying this capability

forbesgillikin commented 1 year ago

I discovered some potentially useful information for this. Users who are experiencing this issue do not have the app in their notification settings at all. Meaning the app is missing entirely from Settings > Notifications.

Deleting and reinstalling the app does not help in any way. It appears this is an issue with the app registering for notifications with the device entirely, and not just related to the token.

Biplovkumar commented 1 year ago
    "@react-native-firebase/app": "^18.3.1",
    "@react-native-firebase/messaging": "^18.3.1",
    "react": "18.2.0",
    "react-native": "0.72.4",

Same error here! Please solve.

Biplovkumar commented 1 year ago

I discovered some potentially useful information for this. Users who are experiencing this issue do not have the app in their notification settings at all. Meaning the app is missing entirely from Settings > Notifications.

Deleting and reinstalling the app does not help in any way. It appears this is an issue with the app registering for notifications with the device entirely, and not just related to the token.

It will give exact error. So that user can solve it.

forbesgillikin commented 1 year ago

I discovered some potentially useful information for this. Users who are experiencing this issue do not have the app in their notification settings at all. Meaning the app is missing entirely from Settings > Notifications. Deleting and reinstalling the app does not help in any way. It appears this is an issue with the app registering for notifications with the device entirely, and not just related to the token.

It will give exact error. So that user can solve it.

I found that requesting permission for notifications can re-register a device and get them out of this state. Here is my work around

try {
   await firebase.messaging().registerDeviceForRemoteMessages();
   const fcmToken = await messaging().getToken();
    // do something with the token
} catch () {
    await messaging().requestPermission();
}
Biplovkumar commented 1 year ago

I discovered some potentially useful information for this. Users who are experiencing this issue do not have the app in their notification settings at all. Meaning the app is missing entirely from Settings > Notifications. Deleting and reinstalling the app does not help in any way. It appears this is an issue with the app registering for notifications with the device entirely, and not just related to the token.

It will give exact error. So that user can solve it.

I found that requesting permission for notifications can re-register a device and get them out of this state. Here is my work around

try {
   await firebase.messaging().registerDeviceForRemoteMessages();
   const fcmToken = await messaging().getToken();
    // do something with the token
} catch () {
    await messaging().requestPermission();
}

@forbesgillikin then i am getting same error.

[Error: [messaging/unregistered] You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages()

"@react-native-firebase/app": "^18.3.1",
"@react-native-firebase/messaging": "^18.3.1",
"react": "18.2.0",
"react-native": "0.72.4",
kakakalot commented 1 year ago

[Error: [messaging/unregistered] You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages().]

I also facing the above issue after upgrading "@react-native-firebase/messaging" from 16.4.3 to 18.4.0. Furthermore, I can provide more detail Use cases:

  1. App's fresh installation, open app, show notification permission alert, click allow. the token is available via messaging().onTokenRefresh. Then the app submits token to api and receive push notification successfully.
  2. Force close or reinstall app, then open. The notification permission alert does not show and we got the above error message when calling getToken
SirCameron commented 1 year ago

@forbesgillikin permissions for notifications are allowed on my app and I still get this error.

xerdnew commented 1 year ago

I am also getting the same error. Any solution yet?

    "@react-native-firebase/app": "^18.5.0",
    "@react-native-firebase/auth": "^18.5.0",
    "@react-native-firebase/messaging": "^18.5.0",
    "react": "18.2.0",
    "react-native": "0.72.5",

Running on iPhone 14 simulator with iOS 16.4

nmluancs commented 1 year ago

I think you forgot to enable push notification capability.

Click on .xcodeproj -> Capabilities -> Enable Push Notification

SirCameron commented 1 year ago

@nmluancs nope, added for debug and production...

kakakalot commented 1 year ago

Finally, after 1 month, I fixed this issus by using [[UIApplication sharedApplication] registerForRemoteNotifications]; instead of await messaging().registerDeviceForRemoteMessages()

My AppDelegate.mm file

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>

#import "RNFBMessagingModule.h"
#import <Firebase.h>
#import "RNSplashScreen.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }

  [FIRApp configureWithName:@"secondaryFromNative" options:[FIROptions defaultOptions]];
  // Add this line
  [[UIApplication sharedApplication] registerForRemoteNotifications];

  self.moduleName = @"SampleRN";
  self.initialProps = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:@{}];

  [super application:application didFinishLaunchingWithOptions:launchOptions];

  [RNSplashScreen show];  // here
  return YES;
}

- (BOOL)application:(nonnull UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 12000) /* __IPHONE_12_0 */
    (nonnull void (^)(NSArray<id <UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
  (nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif
  return NO;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

@end
vauruk commented 1 year ago

I followed all the tips but for me not worked until now. Someone other things to resolve the problem.

nvdnvd00 commented 11 months ago

I've tried everything mentioned above, but nothing seems to work.

"react-native": "0.72.4",
"@react-native-firebase/app": "18.5.0",
"@react-native-firebase/auth": "18.5.0",
"@react-native-firebase/firestore": "18.5.0",
"@react-native-firebase/messaging": "^18.6.1",
vauruk commented 11 months ago

I used this way to pass off the problem of not registering etc, but I have another problem, I don't receive a message from firebase in iOS, in android it is ok! this is my solution for now install this version:

"@react-native-firebase/analytics": "16.5.0",
"@react-native-firebase/app": "16.5.0",
"@react-native-firebase/messaging": "16.5.0",

I hope helped anyone.

mikehardy commented 11 months ago

I see people posting with version numbers that are not identical between all the react-native-firebase components: do not do that.

All versions should be the same --> https://invertase.io/blog/react-native-firebase-versioning

I see people posting that they have problems, but they are not using current versions of the software: do not do that

We issue new versions because they solve problems, and they could very well solve the problem you are experiencing. You would not want to spend a lot of time troubleshooting a problem with one of your users that you already fixed in your own software would you? You should not expect that here either.

nvdnvd00 commented 11 months ago

I see people posting with version numbers that are not identical between all the react-native-firebase components: do not do that.

All versions should be the same --> https://invertase.io/blog/react-native-firebase-versioning

I see people posting that they have problems, but they are not using current versions of the software: do not do that

We issue new versions because they solve problems, and they could very well solve the problem you are experiencing. You would not want to spend a lot of time troubleshooting a problem with one of your users that you already fixed in your own software would you? You should not expect that here either.

Even though I set all versions to be the same, the issue still persists (18.5.0/18.6.1). Please let me know if you want more information!

mikehardy commented 11 months ago

Interesting, thank you for aligning versions and (hopefully...) using the current version (18.6.1) with the current version of firebase-ios-sdk (10.17.0 - you will get this automatically assuming you do not override the version)

There are a few reasons you might not receive messages:

Which of these is affecting you? Which is the problem? With an issue that has 70 comments, I bet every single one of these reasons is "the reason" for at least one person. Unfortunately that makes it impossible to ever close this issue (so many people! so many different issues!) and it makes it very difficult to handle each specific person (which reason is their reason?)

That's the best advice I can give to start troubleshooting this stuff.

I am using a real device with a release build of the current firebase-ios-sdk and I am able to successfully receive FCM from it, so it is definitely possible for this to work. But it is difficult

Akifcan commented 11 months ago

in ios simulator Authorization status: 1 but I can't get the device token(same error)

Akifcan commented 11 months ago

we tested on testlight now and notifications worked

rmontana2023 commented 11 months ago

I'm still having this issue , when i released my app in test flight it cant generate token but in development mode it is working. any work around for this ?

rmontana2023 commented 11 months ago

we tested on testlight now and notifications worked

How did you fix it ?

AlkanV commented 11 months ago

we have same problem on iPhone 8 running on a iOS 15. these are my firebase related packages. i also tried iphone 14, running on a iOS 16.2, but it is not happening. it looks like it is happening on lower iOS versions.

"@react-native-firebase/analytics": "^16.4.6",
"@react-native-firebase/app": "^16.4.6",
"@react-native-firebase/app-distribution": "^16.4.6",
"@react-native-firebase/crashlytics": "^16.4.6",
"@react-native-firebase/messaging": "^17.4.3",
"@react-native-firebase/perf": "^16.4.6",
mikehardy commented 11 months ago

@AlkanV you have mismatched firebase package versions, that is not supportable --> https://invertase.io/blog/react-native-firebase-versioning

You also have outdated package versions which is not something to approach support with as anyone involved (including yourself...) may waste precious time chasing an issue that is already fixed in current versions. Update to current, retest, re-post if still occurring please

rmontana2023 commented 11 months ago

Hi @mikehardy i already update my firebase package version

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

But i still encounter inconsistency in generating the apns token when the app is released/testflight I try it on multiple devices some device that is not connected to wifi only cellular data the APNS token is working. Any help on this ?

mikehardy commented 11 months ago

I'm sorry, I'm not sure why it is inconsistent. I have not experienced this that I'm aware of. This would be a workaround, but perhaps if you retried a few times it might come through? It is a network-dependent process so maybe there is something to do with network access / network blocking on the wifi network or maybe there is latency or something and a retry would work.

rmontana2023 commented 11 months ago

Thank you, and also in my local environment apns token is working but when i upload my app to testflight fcm token is null.

ateeq4112 commented 10 months ago

Add push notification capability on tab singing & Capabilities in xcode and then rebuild project.

incom-app-ru commented 9 months ago

I had this problem. I was able to solve it.

In XCode - Signing & Capabilities. add Background fetch & add Remote notification (Background Modes) add Push Notifications

for Debug and for Release separately!

github-actions[bot] commented 9 months ago

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.

timorss commented 8 months ago

still happens

kakakalot commented 8 months ago

still happens

@timorss , Did you try my solution? It is here

timorss commented 8 months ago

still happens

@timorss , Did you try my solution? It is here

yes

image

timorss commented 8 months ago

I didnt add push notifications, I Solved it by adding it image

https://rnfirebase.io/messaging/usage/ios-setup

tungne commented 4 months ago

I didnt add push notifications, I Solved it by adding it image

https://rnfirebase.io/messaging/usage/ios-setup

This is the solution that helped me solve the problem. Thanks, bro.

Kaijonsson commented 3 months ago

I found a pretty ugly workaround, but it works for me as for now. Skärmavbild 2024-07-03 kl  14 39 38

Hope it can get people forward while waiting for a proper solution.

jaaywags commented 2 months ago

I get this error on a fresh expo project running on iOS Simulator on my M3 Mac

You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages().

I tried both with and without await messaging().registerDeviceForRemoteMessages();.

I have the aps-environment entitlement in my app.json

{
  "expo": {
    ...
    "ios": {
      ...
      "entitlements": {
        "aps-environment": "production"
      }
    },
...
}

I also added the p8 file to firebase and made sure all my certificates and keys are setup correctly in the apple developer console.

I even tried calling setAPNSToken with no avail.