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.63k stars 2.2k forks source link

:fire: [🐛] iOS Crash: -[__NSCFNumber componentsSeparatedByString:]: unrecognized selector sent to instance 0x9b8e80 #7913

Closed ericlathrop closed 1 month ago

ericlathrop commented 1 month ago

Issue

My app was working last week. I updated some non-firebase libraries or something on Android, and when I returned to the iOS build, I get this crash.

2024-07-17 12:55:28.665334-0400 HorseRacingNation[1066:25635] You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
2024-07-17 12:55:28.665414-0400 HorseRacingNation[1066:25635] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
2024-07-17 12:55:28.671714-0400 HorseRacingNation[1066:25635] -[__NSCFNumber componentsSeparatedByString:]: unrecognized selector sent to instance 0x9b8e80b9a08c4c96
2024-07-17 12:55:28.672837-0400 HorseRacingNation[1066:25635] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber componentsSeparatedByString:]: unrecognized selector sent to instance 0x9b8e80b9a08c4c96'
*** First throw call stack:
(0x181063c60 0x198893ee4 0x1811346e8 0x180ffd54c 0x180ffc75c 0x104504df0 0x104502f94 0x104502bc4 0x107749fc8 0x10774b934 0x104502b80 0x1044d3b0c 0x1043fc548 0x104401b28 0x1044016f8 0x104400ba0 0x1044005c4 0x104400528 0x10417004c 0x183615574 0x1837e9d98 0x1837d34bc 0x183641284 0x1834a7fa8 0x1835ca9dc 0x1836e0008 0x183908434 0x183898174 0x1834a8cf4 0x1835648e4 0x1834aaa84 0x18358f134 0x1839e4f38 0x1834d872c 0x18351a4cc 0x183645cec 0x18358d550 0x1921f3c50 0x192215f98 0x1921d6bdc 0x1921d7fd4 0x107749fc8 0x10774d4cc 0x1921d82ac 0x1921d77c0 0x1921db960 0x181084448 0x181094578 0x180fd6734 0x180fdbe08 0x180fef174 0x1a1b2e988 0x1837f1a88 0x18358af78 0x1041707d4 0x1078c44d0)
libc++abi: terminating with uncaught exception of type NSException

The crash happens in FirebaseCore/Sources/FIRApp.m image

It's an expo project.

Things I've tried:

  1. I've updated to the latest dependencies.
  2. I've run pod repo update and pod update
  3. I've tried the command-line build npx expo run:ios and building through Xcode
  4. I've also tried deleting the entire ios folder and regenerating with npx expo prebuild

I'm sorry, but I don't really know much about Macs, OSX, Objective-C, or Swift.

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "horse-racing-nation-mobile", "version": "2.1.3", "main": "expo-router/entry", "scripts": { "start": "expo start", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@react-native-async-storage/async-storage": "^1.24.0", "@react-native-firebase/analytics": "^20.2.1", "@react-native-firebase/app": "^20.2.1", "@react-native-firebase/messaging": "^20.2.1", "@react-native-firebase/remote-config": "^20.2.1", "date-fns": "^3.6.0", "expo": "^51.0.21", "expo-build-properties": "~0.12.3", "expo-constants": "~16.0.2", "expo-dev-client": "~4.0.20", "expo-font": "~12.0.6", "expo-linear-gradient": "~13.0.2", "expo-linking": "~6.3.1", "expo-router": "~3.5.18", "expo-status-bar": "~1.12.1", "expo-store-review": "~7.0.2", "react": "18.2.0", "react-native": "0.74.3", "react-native-google-mobile-ads": "^14.1.0", "react-native-safe-area-context": "^4.10.8", "react-native-screens": "^3.31.1", "react-native-webview": "^13.10.5" }, "devDependencies": { "@babel/core": "^7.20.0" }, "private": true } ``` #### `firebase.json` for react-native-firebase v6: ```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 'json' podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {} ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0' ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR'] platform :ios, podfile_properties['ios.deploymentTarget'] || '13.4' install! 'cocoapods', :deterministic_uuids => false prepare_react_native_project! target 'HorseRacingNation' do use_expo_modules! config = use_native_modules! use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS'] use_react_native!( :path => config[:reactNativePath], :hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes', # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/..", :privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] != 'false', ) post_install do |installer| react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, :ccache_enabled => podfile_properties['apple.ccacheEnabled'] == 'true', ) # This is necessary for Xcode 14, because it signs resource bundles by default # when building for devices. installer.target_installation_results.pod_target_installation_results .each do |pod_name, target_installation_result| target_installation_result.resource_bundle_targets.each do |resource_bundle_target| resource_bundle_target.build_configurations.each do |config| config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end end end end post_integrate do |installer| begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end end end ``` #### `AppDelegate.mm`: ```objc #import "AppDelegate.h" #import #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // @generated begin @react-native-firebase/app-didFinishLaunchingWithOptions - expo prebuild (DO NOT MODIFY) sync-ecd111c37e49fdd1ed6354203cd6b1e2a38cccda [FIRApp configure]; // @generated end @react-native-firebase/app-didFinishLaunchingWithOptions self.moduleName = @"main"; // 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:@".expo/.virtual-metro-entry"]; #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

#### 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:** ``` (node:87926) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) System: OS: macOS 14.5 CPU: (4) x64 Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz Memory: 39.44 MB / 8.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 22.2.0 path: /usr/local/bin/node Yarn: Not Found npm: version: 10.8.1 path: /usr/local/bin/npm Watchman: version: 2024.05.06.00 path: /usr/local/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /usr/local/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: Not Found Xcode: version: 15.4/15F31d path: /usr/bin/xcodebuild Languages: Java: Not Found 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.3 wanted: 0.74.3 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-firebase` version you're using that has this issue:** - `20.2.1` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `N` & `VERSION`


ericlathrop commented 1 month ago

I've fixed these warnings:

2024-07-17 12:55:28.665334-0400 HorseRacingNation[1066:25635] You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
2024-07-17 12:55:28.665414-0400 HorseRacingNation[1066:25635] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.

and I still get the same error on a physical device.

On the simulator, I'm now getting:

Error: xcrun simctl install 6AFEBED8-ED33-400B-93B1-5DFB3D47622E /Users/ericlathrop/Library/Developer/Xcode/DerivedData/HorseRacingNation-etzltayffrbasmapnqzwyfhbyaqm/Build/Products/Debug-iphonesimulator/HorseRacingNation.app exited with non-zero code: 22
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Simulator device failed to install the application.
The application's Info.plist does not contain a valid CFBundleVersion.
Ensure your bundle contains a valid CFBundleVersion.
Underlying error (domain=NSPOSIXErrorDomain, code=22):
        Failed to install the requested application
        The application's Info.plist does not contain a valid CFBundleVersion.
Lyokone commented 1 month ago

It looks like you didn't follow this setup step: https://rnfirebase.io/messaging/usage/ios-setup

For your current error, it looks like a simple fix inside of Xcode is required: https://stackoverflow.com/questions/43111501/the-bundles-info-plist-does-not-contain-a-cfbundleversion-key-or-its-value-is-n

ericlathrop commented 1 month ago

@Lyokone Sorry, it looks like you didn't read my comment https://github.com/invertase/react-native-firebase/issues/7913#issuecomment-2236938694 where I said I fixed those warnings and added those capabilities in your first link. They got removed when I deleted the auto-generated ios folders. I re-added them, and still get the same issue.

The CFBundleVersion is a simulator-only issue, and I've tried the change in your second link and it didn't change anything. On the real device I still get the original error.

This issue is not solved in any way, please re-open.

ericlathrop commented 1 month ago

I did a binary search of my commits to find the change that caused this crash. It turns out adding a buildNumber to the ios section of my app.json causes the crash. This also causes the issue with the simulator.

diff --git a/clients/horse-racing-nation-mobile/app.json b/clients/horse-racing-nation-mobile/app.json
index 4ceb5bd4e8..d39b6733f6 100644
--- a/clients/horse-racing-nation-mobile/app.json
+++ b/clients/horse-racing-nation-mobile/app.json
@@ -15,12 +15,13 @@
       "**/*"
     ],
     "ios": {
+      "buildNumber": 21,
+      "bundleIdentifier": "com.horseracingnationmobile",
       "entitlements": {
         "aps-environment": "production"
       },
-      "supportsTablet": true,
-      "bundleIdentifier": "com.horseracingnationmobile",
-      "googleServicesFile": "./config/GoogleService-Info.plist"
+      "googleServicesFile": "./config/GoogleService-Info.plist",
+      "supportsTablet": true
     },
     "android": {
       "adaptiveIcon": {
@@ -28,7 +29,8 @@
         "backgroundColor": "#222222"
       },
       "googleServicesFile": "./config/google-services.json",
-      "package": "com.horseracingnationmobile"
+      "package": "com.horseracingnationmobile",
+      "versionCode": 20100
     },
     "notification": {
       "icon": "./assets/images/icons/notification_small.png"
davevilela commented 1 month ago

@ericlathrop can you elaborate on what is actually causing the problem? I always used buildNumber on app.json and never had any problem. I don't understand what's going on.

ericlathrop commented 1 month ago

@davevilela Everything I know is documented in this issue. Sorry, but I'm not much of a native dev. I probably made a dozen builds to find the diff above that caused my app to crash. Reverting makes the app run.