React Native firebase 消息传递

问题描述 投票:0回答:1
import { initializeApp } from 'firebase/app';
import { getAuth, signInWithPhoneNumber, PhoneAuthProvider,signInWithCredential } from 'firebase/auth';
import { getMessaging } from 'firebase/messaging';

const firebaseConfig = {
This is config
};

const app = initializeApp(firebaseConfig);
const messaging = getMessaging(app); // problem is on this line
const auth = getAuth(app);

export { auth, signInWithPhoneNumber, PhoneAuthProvider,signInWithCredential,messaging};`

它显示此错误 TypeError:无法读取未定义的属性“addEventListener”

react-native expo firebase-cloud-messaging
1个回答
0
投票

以下是排查和解决问题的方法:

import { initializeApp } from 'firebase/app';
import { getAuth, signInWithPhoneNumber, PhoneAuthProvider, signInWithCredential } from 'firebase/auth';
import { getMessaging, isSupported } from 'firebase/messaging';

const firebaseConfig = {
  // Your Firebase config here
};

const app = initializeApp(firebaseConfig);

let messaging;
isSupported().then((supported) => {
  if (supported) {
    messaging = getMessaging(app);
  } else {
    console.warn('Firebase Messaging is not supported in this environment.');
  }
});

const auth = getAuth(app);

export { auth, signInWithPhoneNumber, PhoneAuthProvider, signInWithCredential, messaging };
© www.soinside.com 2019 - 2024. All rights reserved.