Reputation: 129
I am upgrading my app to react-native 0.61.2 so I had to upgrade react-native-firebase to 6.0.3,I start with adding @react-native-firebase/app
and @react-native-firebase/messaging
packages.
import { Platform } from 'react-native'
import { firebase } from '@react-native-firebase/messaging'
// pluck values from your `GoogleService-Info.plist` you created on the firebase console
const iosConfig = {
clientId: '...',
appId: '...',
apiKey: '...',
databaseURL: '...',
storageBucket: '...',
messagingSenderId: '...',
projectId: '...',
persistence: true,
}
// pluck values from your `google-services.json` file you created on the firebase console
const androidConfig = {
clientId: '...',
appId: '...',
apiKey: '...',
databaseURL: '...',
storageBucket: '...',
messagingSenderId: '...',
projectId: '...',
persistence: true,
}
const firebaseApp = firebase.initializeApp(
// use platform-specific firebase config
Platform.OS === 'ios' ? iosConfig : androidConfig,
// name of this app
'myApp'
)
export default firebaseApp
on my file I am doing this
import firebaseApp from '...path to/firebaseApp'
.
.
.
async checkPermission() {
console.warn('checkPermission firebaseApp : ', firebaseApp)
const enabled = await firebaseApp.messaging().hasPermission()
if (!enabled) {
this.requestPermission()
}
this.syncToken()
}
.
.
.
I am getting next warnings:
Warning #1:
checkPermission firebaseApp : {"_40": 0, "_55": {"_automaticDataCollectionEnabled": false, "_deleteApp": [Function bound deleteApp], "_deleted": false, "_initialized": false, "_intialized": true, "_name": "...", "_nativeInitialized": false, "_options": {"apiKey": "...", "appId": "...", "clientId": "...", "databaseURL": "...", "debug": true, "messagingSenderId": "...", "projectId": "...", "storageBucket": "..."}}, "_65": 1, "_72": null}
Warning #2:
Possible Unhandled Promise Rejection (id: 0):
TypeError: _firebaseApp.default.messaging is not a function. (In '_firebaseApp.default.messaging()', '_firebaseApp.default.messaging' is undefined)
am I doing something wrong, any help?
Thank you all.
Upvotes: 1
Views: 1531
Reputation: 2638
From react native 0.60.0. React native introduce Autolinking library feature, so there is no need to manually linking library or npm in android and ios, but we are used some old packages and libraries. Those npm(react-native-firebase) are not updated according to new version of react native, so we need to link those libraries and packages manually.
You need to check firebase npm manually linking process.
1. import package name into MainActivity.java
file
2. Add following dependency in app
level build.gradle
file
3. Add classpath
in project
level build.gradle
file
Upvotes: 0
Reputation: 129
I should use the default app
so in my initializeApp
I removed the second option myApp
and
this method changed to be
async checkPermission() {
console.warn('checkPermission firebaseApp : ', firebaseApp)
firebaseApp
const enabled = await firebase.messaging().hasPermission()
if (!enabled) {
this.requestPermission()
}
this.syncToken()
}
reading firebase from
import firebase from '@react-native-firebase/app'
import '@react-native-firebase/messaging'
Upvotes: 1