React Native:应用程序关闭时 运行 在 iOS 上执行后台任务的最佳方法?

React Native: Best approach to run a background task on iOS when the app is closed?

我需要定期向服务器发送 HealthKit 数据。我正在使用 React Native 和 rn-apple-healthkit。我试过 react-native-background-task,但是当应用程序关闭时它不会工作(不是后台模式)。我在 Apple 开发者文档中读到它是有意设计的。

我在网上找到了一些解决方案,例如地理定位服务、运行 套接字和 "playing" 静音、搭载推送通知,但它们似乎都是解决方法。

2019年有什么好的方法吗?

使用静默通知是实现此目的的正确方法。然而,当 phone 被锁定时它不会工作:

For security, the HealthKit store is encrypted when the device is locked, and the HealthKit store can only be accessed by an authorized app. As a result, you may not be able to read data from the store when your app is launched in the background; however, apps can still write data to the store, even when the phone is locked.

取自https://developer.apple.com/documentation/healthkit/protecting_user_privacy