vitorpamplona / react-native-ble-advertiser

Bluetooth Advertiser/Scanner for React Native.
60 stars 38 forks source link

Scanner and Broadcast not working when app is in background #20

Closed Sohailbhutto closed 3 years ago

Sohailbhutto commented 3 years ago

How to keeps scanner and broadcasting running even app is in background for both android and ios. Please share the code snippet.

vitorpamplona commented 3 years ago

Background processing has been severely limited by both Android and iOS in the latest months. iOS will kill any process that is running in the background for over 15 mins. Android is easier, but it can also kill the process. On Android, you have to register a service to start the adv and scanning there.

Try using the https://www.npmjs.com/package/react-native-background-fetch to register the services and run Scheduled tasks that activate both scanning and advertising.

Sohailbhutto commented 3 years ago

@vitorpamplona can you please share the example code using https://www.npmjs.com/package/react-native-background-fetch

vitorpamplona commented 3 years ago

You can see the Android Background running here: https://github.com/vitorpamplona/ble-tracker-client

I am not sure how to use it on iOS (not required for the app I made)

Sohailbhutto commented 3 years ago

@vitorpamplona correction. For background, i mean to say that app is not killed, app is in background. In my scenario i just want to scan and broadcast when app is in foreground or background, not the case that app is killed.

Sohailbhutto commented 3 years ago

@vitorpamplona i want to implement the scenario like this app, app is in foreground or background, but not killed. https://www.tracetogether.gov.sg/

vitorpamplona commented 3 years ago

Then you can probably use the https://www.npmjs.com/package/react-native-background-fetch library.