贵有恒,何必三更起、五更眠、最无益,只怕一日曝、十日寒。这篇文章主要讲述TypeError(RN 0.61.2):_ firebaseApp.default.messaging不是函数相关的知识,希望能为你提供帮助。
我将我的应用程序升级到react-native-0.61.2,所以我不得不将react-native-firebase升级到6.0.3,我从添加@react-native-firebase/app
和@react-native-firebase/messaging
包开始。
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
在我的档案上,我正在这样做
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()
}
.
.
.
我要下一个警告:
警告#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}
警告#2:
Possible Unhandled Promise Rejection (id: 0):
TypeError: _firebaseApp.default.messaging is not a function. (In '_firebaseApp.default.messaging()', '_firebaseApp.default.messaging' is undefined)
我做错什么了,有什么帮助吗?
谢谢大家。
答案我应该使用默认应用因此在
initializeApp
中,我删除了第二个选项myApp
和此方法更改为async checkPermission() {
console.warn('checkPermission firebaseApp : ', firebaseApp)
firebaseApp
const enabled = await firebase.messaging().hasPermission()
if (!enabled) {
this.requestPermission()
}
this.syncToken()
}
【TypeError(RN 0.61.2)(_ firebaseApp.default.messaging不是函数)】从'@ react-native-firebase / app'导入firebase导入'@ react-native-firebase / messaging'
推荐阅读
- 由于ZIP的结构,使用kudu ZipDeploy的Azure webapp部署失败
- 是否可以在手机上远程构建和运行Android Studio应用()
- 如何在Symfony 3中将Twig正确地包含和使用jQuery
- 如何在Symfony 3中基于数字值(YouTube或URL Shortener样式)创建非顺序唯一ID
- Symfony服务”uri_signer”依赖于不存在的参数”kernel.secret”
- 如何在C#WinForms中使用NAudio从MP3音频文件渲染音频波形图像
- 如何在Winforms C#中使用DarkUI(黑暗用户界面)
- 如何在Symfony 3中使用PHP将PDF转换为文本(从PDF提取文本)
- 你需要了解的有关SQLite Mobile数据库的所有信息