vitorpamplona / react-native-ble-advertiser

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

Advertising in background #14

Closed AleeeKoi closed 4 years ago

AleeeKoi commented 4 years ago

Hello, Does app keeps advertising in background (iOS/Android both)?

Thank you

vitorpamplona commented 4 years ago

Hi AleeeKoi,

The idea is to provide a way to Advertise and Scan. If its background or foreground it depends on how you integrate it. The lib simply calls iOS and Android functions.

AleeeKoi commented 4 years ago

Hi @vitorpamplona, Let me explain better with a practical use: If i start an advertising service in foreground and never stop it, does it live when app is in background or closed? Thank you

vitorpamplona commented 4 years ago

It's just like a memory leak. Different phones will have different behaviors. iOS will kill it instantly. Androids will run for some time and a few phones will adjust the signal strength and frequency to lower and lower until the OS turns it off. Also, in the case where the Android phone is low in memory, it will kill the app as soon as it can, including the Advertising function.

AleeeKoi commented 4 years ago

Ok. So let me understand, do you think it's not possible to create a ble advertising with some gatt services and keep it alive in foreground and background until some manual user event kill it? In my case, I need to create some services and characteristics from the phone and maintain them active and discoverable from other devices even if the app that make the gatt server is in background mode. Thank you

vitorpamplona commented 4 years ago

Sorry for the delay, @AleeeKoi.

Yes. Phone manufacturers set their priorities on when to kill background advertising. Some last a few hours, some will kill as soon as the app goes to background. Apple, for instance, is VERY strict on advertising.

If you have a given ServiceUUID, the scanning is quite stable though. Just don't expect the app will let you know every time it sees the service. If it is too much, the manufacturer will also kill the service.