我正在使用 zo0r react-native-push-notification图书馆。
"react": "16.0.0-alpha.12",
"react-native": "^0.45.1",
"react-native-push-notification": "^3.0.0"
每次我打开应用程序时都会运行此代码:
PushNotification.configure({
onNotification: function(notification) {
console.log('onNotification');
ToastAndroid.show('onNotification', 3000);
}
});
我从后台服务发送本地推送通知:
PushNotification.localNotification({
message: 'Hello World',
smallIcon: 'ic_launcher'
});
通知已送达。当我点击它时,onNotification
方法没有被调用,然后当我收到另一个通知时,它实际上被调用了。似乎只有当应用程序在内存 atm 中时它才有效。
我做错了什么吗?
我开了一个GitHub issue
最佳答案
这是常见问题,使用启动画面时会出现该问题。 像这样编辑 list :
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter>
</activity>
关于android - react native 推送通知 onNotification 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45616252/