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

🔥 [🐛] Firebase Messaging refuses to work on iOS - Error in application:didFailToRegisterForRemoteNotificationsWithError: (null) #8081

Open filiphosko opened 2 days ago

filiphosko commented 2 days ago

Issue

Hello, as the title says, I have trouble running Firebase Messaging on iOS. To make it more frustrating, the error messages I get tell me exactly nothing - but maybe you'll be able to decipher them.

I test this in development, with my iPhone 11 connected to my MB Pro (M2 Pro) with Apple's Lightning -> USB-C cable (but I also tried this with a simulator, iPhone 16). I went over the setup multiple times - I have my APN key uploaded into Firebase Console, got the Google plist in my project. I have the Push Notifications and Background Modes capability enabled (with sub modes too). I have Push Notifications enabled in my app identifier. I also modified AppDelegate.mm and the Podfile, run pod install. I also use this library for a long time, so I already did the setup in the past (and it worked), I just needed to upgrade React Native to a more up-to-date version, so I also updated some of the libs. I never had such an issue with this lib where I even don't get a more detailed error message.

I get the first error when the app starts and the Firebase lib starts to initialize modules. Crashes and analytics are enabled fine, with messages I get this error - [FirebaseMessaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: (null).

Then in JavaScript I try to request permissions, I get this error - [messaging/unknown] The operation couldn’t be completed. (UNErrorDomain error 1.)


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "MyTroubledApp", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest" }, "dependencies": { "@react-native-async-storage/async-storage": "^2.0.0", "@react-native-clipboard/clipboard": "^1.14.1", "@react-native-firebase/analytics": "^21.2.0", "@react-native-firebase/app": "^21.2.0", "@react-native-firebase/crashlytics": "^21.2.0", "@react-native-firebase/messaging": "^21.2.0", "@react-native-masked-view/masked-view": "^0.3.1", "@react-native-picker/picker": "^2.8.1", "@react-navigation/drawer": "^6.7.2", "@react-navigation/elements": "^1.3.31", "@react-navigation/native": "^6.1.18", "@react-navigation/stack": "^6.4.1", "@reduxjs/toolkit": "^2.2.7", "ably": "^2.3.1", "color": "^4.2.3", "js-base64": "^3.7.7", "lodash-es": "^4.17.21", "moment": "^2.30.1", "native-base": "^2.15.2", "react": "18.3.1", "react-native": "0.75.2", "react-native-calendars": "^1.1306.0", "react-native-exit-app": "^2.0.0", "react-native-extended-stylesheet": "^0.12.0", "react-native-gesture-handler": "^2.18.1", "react-native-linear-gradient": "^2.8.3", "react-native-reanimated": "^3.15.1", "react-native-restart": "^0.0.27", "react-native-safe-area-context": "^4.10.9", "react-native-screens": "^3.34.0", "react-native-swiper": "^1.6.0", "react-redux": "^9.1.2", "redux-persist": "^6.0.0", "shortid": "^2.2.16" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/babel-preset": "0.75.2", "@react-native/eslint-config": "0.75.2", "@react-native/metro-config": "0.75.2", "@react-native/typescript-config": "0.75.2", "@types/lodash-es": "^4.17.12", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "eslint": "^8.19.0", "jest": "^29.6.3", "prettier": "2.8.8", "react-native-dotenv": "^3.4.11", "react-test-renderer": "18.3.1", "typescript": "5.0.4" }, "resolutions": { "@react-native-picker/picker": "2.8.1" }, "engines": { "node": ">=18" }, "packageManager": "yarn@3.6.4" } ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "crashlytics_debug_enabled": false } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( "react-native/scripts/react_native_pods.rb", {paths: [process.argv[1]]}, )', __dir__]).strip platform :ios, min_ios_version_supported prepare_react_native_project! $RNFirebaseAnalyticsWithoutAdIdSupport = true linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym end target 'MyTroubledApp' do config = use_native_modules! use_frameworks! :linkage => :static $RNFirebaseAsStaticFramework = true use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'MyTroubledAppTests' do inherit! :complete # Pods for testing end post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, # :ccache_enabled => true ) end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; self.moduleName = @"MyTroubledApp"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [self bundleURL]; } - (NSURL *)bundleURL { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } @end ```


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`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 14.7 CPU: (12) arm64 Apple M2 Pro Memory: 386.55 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 21.7.1 path: ~/.asdf/installs/nodejs/21.7.1/bin/node Yarn: version: 3.6.4 path: ~/.asdf/installs/nodejs/21.7.1/bin/yarn npm: version: 10.5.0 path: ~/.asdf/plugins/nodejs/shims/npm Watchman: version: 2024.08.19.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /Users/filiphosko/.asdf/shims/pod SDKs: iOS SDK: Platforms: - DriverKit 24.0 - iOS 18.0 - macOS 15.0 - tvOS 18.0 - visionOS 2.0 - watchOS 11.0 Android SDK: Not Found IDEs: Android Studio: 2024.1 AI-241.18034.62.2411.12169540 Xcode: version: 16.0/16A242d path: /usr/bin/xcodebuild Languages: Java: version: 22.0.2 path: /usr/bin/javac Ruby: version: 3.3.0 path: /Users/filiphosko/.asdf/shims/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.3.1 wanted: 18.3.1 react-native: installed: 0.75.2 wanted: 0.75.2 react-native-macos: Not Found npmGlobalPackages: "*react-native*": Not Found Android: hermesEnabled: Not found newArchEnabled: Not found iOS: hermesEnabled: Not found 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-firebase` version you're using that has this issue:** - 21.2.0, but I had this issue with an older version too, I just upgraded in the midst of debugging - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


mikehardy commented 2 days ago

I saw that :

Then in JavaScript I try to request permissions, I get this error - [messaging/unknown] The operation couldn’t be completed. (UNErrorDomain error 1.)

As well when I was trying to allow messaging permission, when I uninstalled the app, reinstalled it, and restarted the simulator - some combination of that allowed the simulator to finally have things working.

I recognize that's vague, and I apologize for that but I'm pretty methodical when I'm testing things on Notifee and react-native-firebase and I swear I saw that and either a restart or an uninstall/reinstall cycle allowed me to finally get the permissions prompt, accept it, and then things worked for me ? Perhaps worth a try

filiphosko commented 1 day ago

@mikehardy Thanks a lot Mike, I really appreciate you reply - I thought that maybe it could be a glitch in development, I already spent several hours debugging it. I will try doing some reinstalling/restarting, although I already tried that on my iPhone (physical device). What I want to try is to build an ad-hoc staging build to check if the same thing will happen there, just to be sure it's not a dev environment type of glitch.