TypeError(RN 0.61.2):_ firebaseApp.default.messaging不是函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()
  }

从'@ react-native-firebase / app'导入firebase导入'@ react-native-firebase / messaging'

以上是关于TypeError(RN 0.61.2):_ firebaseApp.default.messaging不是函数的主要内容,如果未能解决你的问题,请参考以下文章

获得未处理的拒绝 (TypeError)

TypeError:“NoneType”对象在函数中不可下标

RN_ 错误整理

RN OneSignal _open 事件

机器学习线性回归

机器学习线性回归