我正在这里https://github.com/zo0r/react-native-push-notification的android上进行设置,其中指出localPush和localSchedule通知不需要firebase,但是我收到有关“未初始化默认firebaseapp的错误,请确保调用firebaseapp.initializeapp(context)首先”
在我的app.js中
import PushNotification from "react-native-push-notification";
export default class App extends Component {
constructor(){
PushNotification.configure({
onRegister: function (token) {
console.log("TOKEN:", token);
},
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
});
}
}
在AndroidMainfest.xml中,我从github复制了除RNPushNotificationListener之外的所有内容
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application ....>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
答案 0 :(得分:1)
确保添加了行
requestPermissions: Platform.OS === 'ios',//add this line inside the .configure if u didn't install the firebase
默认requestPrmission为true,但如果您未在PushNotification.configure中的上述行中安装react-native-firebase