问题
I've been doing a few searches on google trying to find a way to run foreground services in react native but I haven't found much about it.
Is anyone aware of how to accomplish this? This is what I mean by foreground service: https://developer.android.com/guide/components/services.html#Foreground
回答1:
I have an example React Native Foreground Service app here. In this example, I'm doing a Bluetooth scan every 10 seconds and attempting to run a Foreground Service so that the scans will continue even if the app isn't in the foreground.
You can remove the call in index.js
that does the BLE scan and you'll have a simple RN Foreground Service example.
回答2:
Here's a package react-native-foreground-service i found, while I was dealing with the same issue.
来源:https://stackoverflow.com/questions/46228999/is-there-any-way-to-run-a-foreground-service-in-react-native