Dhe*_*n M 8 push-notification badge react-native react-native-ios react-native-firebase
我们正在使用React Native Firebase 版本 6消息传递来处理推送通知。从远程通知内容来看,我们无法在 ios 上增加/减少徽章计数。所以我们使用推送通知 ios来设置徽章计数。
当应用程序位于前台和后台时,它运行得很好。但是当应用程序关闭时,我们能够收到通知,但无法更新徽章计数。
messaging().onMessage(async remoteMessage => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
messaging().setBackgroundMessageHandler(async remoteMessage => {
PushNotificationIOS.getApplicationIconBadgeNumber(number => {
PushNotificationIOS.setApplicationIconBadgeNumber(number + 1);
});
asyncstorage.saveItem("remoteMessage", "only one killed message received");
});
Run Code Online (Sandbox Code Playgroud)
当应用程序处于后台状态时,这里setBackgroundMessageHandler正在工作。根据文档,即使应用程序关闭,此方法也应该调用。但事实并非如此。为了获得更多说明,当应用程序终止时,我在该方法中执行了异步存储操作。但它没有按预期工作。
我还添加了服务器端数据,这些数据是我从后端发送的通知,
{
"to":".................",
"notification":{
"title":"Working Good",
"body":"backgroudn noti",
"badge":"1",
"sound":"./app/assets/sound/alert.wav"
},
"priority":"high",
"badge":"1",
"content_available":true
}
Run Code Online (Sandbox Code Playgroud)
我想提一下这些键的一些要点,
通知对象内有一个徽章,每次关闭应用程序时都会将其设置为图标。但无法增加/减少徽章计数。它始终是 1。
添加“content_available”属性后,我能够更新徽章计数。这意味着仅添加 content_available 后,我在setBackgroundMessageHandler方法中获得了触发器,并使用推送通知 ios 属性更新了徽章计数。
现在,当应用程序关闭时,我在setBackgroundMessageHandler方法中没有收到任何触发器。
即使应用程序已关闭,我是否需要添加任何其他键才能在setBackgroundMessageHandler方法内获取触发器?
我计划尝试使用一些后台库,例如react-native background fetch。但是收到通知后,如果代码中没有任何触发器,我无法触发后台获取库来唤醒应用程序。
那么我怎样才能进入这个方法,同时在应用程序关闭时收到通知呢?
如果需要更多详细信息来澄清该问题,请联系我。感谢您的帮助。
小智 -1
messaging().onMessage
仅当您的应用程序处于后台或前台模式时才有效。
如果您想在应用程序关闭时接收消息,请使用此:
messaging()
.getInitialNotification()
.then(remoteMessage => { console.log(remoteMessage) }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3881 次 |
最近记录: |