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.6k stars 2.19k forks source link

[ 🔥] Error: You attempted to use a firebase module that's not installed on your iOS project by calling firebase.messaging(). #6765

Closed ethanrmiles closed 1 year ago

ethanrmiles commented 1 year ago

Issue

Describe your issue here

After installation of Firebase/App and Firebase/Messaging, I cannot get past the error listed in the title. I have spent the last day (literally a full 6 hours) following solutions that are listed in similar issues, but still to no avail. I have also tried installing Firebase at different versions. Here is how I am calling firebase messaging in the App.js file of my React Native Repo:

import messaging from '@react-native-firebase/messaging';
async function checkApplicationPermission() {
  try{
    const authorizationStatus = await firebase.messaging().requestPermission();
    console.log(authorizationStatus)
  if (authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED) {
    console.log('User has notification permissions enabled.');
  } else if (authorizationStatus === messaging.AuthorizationStatus.PROVISIONAL) {
    console.log('User has provisional notification permissions.');
  } else {
    console.log('User has notification permissions disabled');
  }
  }catch(err){
    console.log(err)
  }
}
 componentDidMount(){
    checkApplicationPermission()
    console.log('anything')
  }

Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@invertase/react-native-apple-authentication": "^2.1.0", "@react-native-async-storage/async-storage": "^1.15.7", "@react-native-community/geolocation": "^2.0.2", "@react-native-community/google-signin": "^5.0.0", "@react-native-community/toolbar-android": "0.1.0-rc.2", "@react-native-firebase/analytics": "^12.1.0", "@react-native-firebase/app": "^12.1.0", "@react-native-firebase/messaging": "^12.9.3", "apsl-react-native-button": "3.0.0", "axios": "^0.24.0", "base-64": "0.1.0", "bcrypt": "^5.0.1", "bcrypt-react-native": "^1.1.1", "buffer": "^6.0.3", "color": "0.11.3", "create-react-class": "^15.6.3", "html-to-text": "^7.1.1", "jsc-android": "^241213.1.0", "jwt-decode": "^3.1.2", "lodash": "4.13.1", "metro-react-native-babel-preset": "^0.55.0", "moment": "2.13.0", "native-base": "^2.15.2", "prop-types": "^15.7.2", "react": "^16.9.0", "react-devtools": "^4.25.0", "react-mixin": "2.0.2", "react-native": "^0.61.5", "react-native-action-button": "2.6.0", "react-native-button": "1.6.0", "react-native-card-view": "0.0.3", "react-native-carousel-view": "^0.5.1", "react-native-checkbox": "1.0.15", "react-native-chooser": "1.5.3", "react-native-credit-card": "0.1.9", "react-native-crypto-js": "^1.0.0", "react-native-deprecated-custom-components": "0.1.0", "react-native-device-info": "^5.5.4", "react-native-easy-toast": "1.0.2", "react-native-email-link": "^1.10.0", "react-native-fbsdk": "^3.0.0", "react-native-geocoding": "^0.3.0", "react-native-geolocation-service": "^5.1.1", "react-native-gesture-handler": "^1.8.0", "react-native-google-places-autocomplete": "^2.1.3", "react-native-htmlview": "^0.16.0", "react-native-image-zoom-viewer": "^2.2.27", "react-native-keyboard-aware-scroll-view": "0.2.7", "react-native-lazyload-deux": "^2.0.4", "react-native-lightbox": "0.6.0", "react-native-linear-gradient": "^2.5.6", "react-native-link-preview": "^1.4.2", "react-native-looped-carousel": "0.0.12", "react-native-material-bottom-navigation": "^0.5.1", "react-native-material-dropdown": "^0.8.0", "react-native-md-textinput": "2.0.4", "react-native-navbar": "1.5.0", "react-native-navigation-bar": "0.1.10", "react-native-pathjs-charts": "0.0.33", "react-native-payments": "^0.8.4", "react-native-progress": "^3.6.0", "react-native-reanimated": "^1.13.2", "react-native-responsive-image": "^2.3.1", "react-native-responsive-screen": "^1.4.2", "react-native-screens": "^2.16.1", "react-native-scrollable-tab-view": "0.5.5", "react-native-selectme": "1.2.3", "react-native-share": "^5.1.4", "react-native-side-menu": "0.20.0", "react-native-simple-radio-button": "2.4.0", "react-native-smart-corner-label": "1.1.1", "react-native-snap-carousel": "^3.9.1", "react-native-swipe-gestures": "^1.0.5", "react-native-swiper": "^1.6.0", "react-native-tab-navigator": "0.3.3", "react-native-textinput-effects": "0.2.0", "react-native-tracking-transparency": "^0.1.0", "react-native-transformable-image": "0.0.18", "react-native-vector-icons": "^8.1.0", "react-native-video": "^5.0.2", "react-native-vimeo": "^0.3.0", "react-native-webview": "^11.13.0", "react-native-webview-autoheight": "^1.0.6", "react-native-youtube": "^2.0.1", "react-native-youtube-iframe": "^2.0.1", "react-navigation": "^3.13.0", "react-redux": "^5.1.2", "react-router": "2.5.2", "react-timer-mixin": "0.13.3", "recyclerlistview": "^1.3.4", "redux": "3.5.2", "redux-immutable-state-invariant": "1.2.3", "redux-thunk": "2.1.0", "sandbox-insights": "^1.0.0", "tcomb-form-native": "^0.6.20", "urbanairship-react-native": "^12.0.0", "validator": "^7.2.0" }, "devDependencies": { "babel-eslint": "^8.0.1", "eslint": "^6.8.0", "eslint-config-airbnb": "^15.0.1", "eslint-config-react": "^1.1.7", "eslint-config-react-native": "^4.1.0", "eslint-loader": "^3.0.4", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^5.0.1", "eslint-plugin-react": "^7.22.0", "graceful-fs": "^4.2.4", "jetifier": "^1.6.5", "prettier": "^2.4.1" } ``` #### `firebase.json` for react-native-firebase v6: ```json { "name": "@react-native-firebase/app", "version": "12.9.3", "author": "Invertase (http://invertase.io)", "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Storage and more.", "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { "build": "genversion --semi lib/version.js && npm run build:version", "build:version": "node ./scripts/genversion-ios && node ./scripts/genversion-android", "build:clean": "rimraf android/build && rimraf ios/build", "build:plugin": "rimraf plugin/build && tsc --build plugin", "lint:plugin": "eslint plugin/src/*", "prepare": "npm run build && npm run build:plugin" }, "repository": { "type": "git", "url": "https://github.com/invertase/react-native-firebase/tree/master/packages/app" }, "license": "Apache-2.0", "keywords": [ "react", "admob", "auth", "config", "digits", "fabric", "functions", "phone-auth", "sms", "firestore", "cloud-firestore", "datastore", "remote-config", "transactions", "react-native", "react-native-firebase", "firebase", "fcm", "apn", "gcm", "analytics", "messaging", "database", "android", "ios", "crash", "firestack", "performance", "firestore", "dynamic-links", "crashlytics" ], "peerDependencies": { "react": "*", "react-native": "*" }, "dependencies": { "@expo/config-plugins": "^4.0.3", "opencollective-postinstall": "^2.0.1", "superstruct": "^0.6.2" }, "publishConfig": { "access": "public" }, "sdkVersions": { "ios": { "firebase": "8.8.0" }, "android": { "minSdk": 16, "targetSdk": 30, "compileSdk": 30, "buildTools": "30.0.2", "firebase": "28.4.2", "firebaseCrashlyticsGradle": "2.7.1", "firebasePerfGradle": "1.4.0", "gmsGoogleServicesGradle": "4.3.10", "playServicesAuth": "19.2.0" } }, "gitHead": "9f00ac9011a710400097302b8263e5c8cf7a6575" } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby platform :ios, '12.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'SandBoxPreviewer' do use_frameworks! use_native_modules! # Unrelated pods here pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app' pod 'FirebaseMessaging', :path => '/path/to/firebase-ios-sdk' # Rest of pods here end post_install do |installer| ## Fix for XCode 12.5 find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm", "_initializeModules:(NSArray> *)modules", "_initializeModules:(NSArray *)modules") find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm", "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))") end def find_and_replace(dir, findstr, replacestr) Dir[dir].each do |name| text = File.read(name) replace = text.gsub(findstr,replacestr) if text != replace puts "Fix: " + name File.open(name, "w") { |file| file.puts replace } STDOUT.flush end end Dir[dir + '*/'].each(&method(:find_and_replace)) end ``` #### `podfile.lock`: ``` DEPENDENCIES: ... - "RNFBApp (from `../node_modules/@react-native-firebase/app`)" ... SPEC REPOS: trunk: ... - Firebase - FirebaseAnalytics - FirebaseCore - FirebaseCoreDiagnostics - FirebaseInstallations - FirebaseMessaging ... SPEC CHECKSUMS: ... Firebase: 629510f1a9ddb235f3a7c5c8ceb23ba887f0f814 FirebaseAnalytics: 5506ea8b867d8423485a84b4cd612d279f7b0b8a FirebaseCore: 98b29e3828f0a53651c363937a7f7d92a19f1ba2 FirebaseCoreDiagnostics: 92e07a649aeb66352b319d43bdd2ee3942af84cb FirebaseInstallations: 40bd9054049b2eae9a2c38ef1c3dd213df3605cd FirebaseMessaging: 419b5c9d84f294a753c6501d8cfb9ced1ce37304 ... PODS: ... - Firebase/Analytics (8.8.0): - Firebase/Core - Firebase/Core (8.8.0): - Firebase/CoreOnly - FirebaseAnalytics (~> 8.8.0) - Firebase/CoreOnly (8.8.0): - FirebaseCore (= 8.8.0) - Firebase/Messaging (8.8.0): - Firebase/CoreOnly - FirebaseMessaging (~> 8.8.0) - FirebaseAnalytics (8.8.0): - FirebaseAnalytics/AdIdSupport (= 8.8.0) - FirebaseCore (~> 8.0) - FirebaseInstallations (~> 8.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/MethodSwizzler (~> 7.4) - GoogleUtilities/Network (~> 7.4) - "GoogleUtilities/NSData+zlib (~> 7.4)" - nanopb (~> 2.30908.0) - FirebaseAnalytics/AdIdSupport (8.8.0): - FirebaseCore (~> 8.0) - FirebaseInstallations (~> 8.0) - GoogleAppMeasurement (= 8.8.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/MethodSwizzler (~> 7.4) - GoogleUtilities/Network (~> 7.4) - "GoogleUtilities/NSData+zlib (~> 7.4)" - nanopb (~> 2.30908.0) - FirebaseCore (8.8.0): - FirebaseCoreDiagnostics (~> 8.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Logger (~> 7.4) - FirebaseCoreDiagnostics (8.15.0): - GoogleDataTransport (~> 9.1) - GoogleUtilities/Environment (~> 7.7) - GoogleUtilities/Logger (~> 7.7) - nanopb (~> 2.30908.0) - FirebaseInstallations (8.15.0): - FirebaseCore (~> 8.0) - GoogleUtilities/Environment (~> 7.7) - GoogleUtilities/UserDefaults (~> 7.7) - PromisesObjC (< 3.0, >= 1.2) - FirebaseMessaging (8.8.0): - FirebaseCore (~> 8.0) - FirebaseInstallations (~> 8.0) - GoogleDataTransport (~> 9.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Reachability (~> 7.4) - GoogleUtilities/UserDefaults (~> 7.4) - nanopb (~> 2.30908.0) ``` #### `AppDelegate.m`: ```objc #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"SandBoxPreviewer" initialProperties:nil launchOptions:launchOptions]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) { return YES; } if ([RNGoogleSignin application:application openURL:url options:options]) { return YES; } if ([RCTLinkingManager application:application openURL:url options:options]) { return YES; } return NO; } @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 12.5.1 CPU: (8) arm64 Apple M1 Memory: 140.69 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 14.0/14A309 - /usr/bin/xcodebuild npmPackages: react: ^16.9.0 => 16.9.0 react-native: ^0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **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:** - `5.6.0` - **`Firebase` module(s) you're using that has the issue:** - `messaging` - **Are you using `TypeScript`?** - `Nope!`


mikehardy commented 1 year ago

Hi there - with apologies, react-native 0.61 and these versions of react-native-firebase:


    "@react-native-firebase/analytics": "^12.1.0",
    "@react-native-firebase/app": "^12.1.0",
    "@react-native-firebase/messaging": "^12.9.3",

Are simply not supportable - they are years old, and in a mobile environment that means critical things - like supporting modern versions of Xcode so you can correctly build for the minimum version of iOS that is even deployable to the App Store or handling things like permissions on Android 13 or privacy issues like ATT on iOS with analytics are simply not handled. So they're not viable.

Before opening an issue in open source repos it really helps to be on current stable releases of things. I have a demo script here that builds a complete react-native + react-native-firebase app from scratch in a fully automated way (you can just read the script) and it should show you how to do the integration with current stable versions so things work https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

If you must persist in using old versions, please don't mix and match the firebase ones (https://invertase.io/blog/react-native-firebase-versioning) and if you cannot find the native module from javascript, make sure you've correctly done pod install and rebuilt the native code prior to trying to access it.

I'm certain - given I provide a fully automated script that demonstrates it building + running correctly - that this is a project specific problem, so with apologies I'll close this as not actionable here as it will not result in a change to this module as far as I can see