gpt4 book ai didi

push-notification - React Native 本地推送通知

转载 作者:行者123 更新时间:2023-12-05 07:07:28 28 4
gpt4 key购买 nike

我正在关注这里的设置 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>

最佳答案

确保添加行

  requestPermissions: Platform.OS === 'ios',//add this line inside the .configure if u didn't install the firebase

默认的 requestPrmission 将为真,但如果您没有安装 react-native-firebase,请在 PushNotification.configure 的上方使用

关于push-notification - React Native 本地推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62141548/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com