在关闭的反应本机应用程序中处理静默推送通知 (Android)?

Handle silent push notification in closed react-native app (Android)?

我正在开发一个大部分时间都关闭的本机反应应用程序。但是,我需要能够将更新从后端发送到不同的客户端,以便他们可以更新本地地理围栏。

我想我可以为此使用静默推送通知(使用 FCM)。当应用程序 运行(在前台或后台)时,这似乎工作正常,但当应用程序关闭时,我无法处理这些推送通知。

我可以在应用程序关闭时处理正常的推送通知,因为当用户按下通知时,应用程序会启动并且通知可用作初始通知,但这不是静默通知。

有什么方法可以让我的应用程序在关闭时处理静默推送通知?是在后台打开,处理通知,然后关闭,还是注册某种后台服务?

你可能想看看 react-native-push-notification#silent

基本上 android:

If your Android app is not running when a silent notification is received then this library will start it. It will be started in the background however, and if the OS starts your app in this way it will not start the react-native lifecycle. This means that if your notification delivery code relies on the react-native lifecycle then it will not get invoked in this situation. You need to structure your app in such a way that PushNotification.configure gets called as a side effect of merely importing the root index.android.js file.

和IOS:

The crucial bit of an iOS silent notification is presence of the "content-available": 1 field.