1

Not able to scan devices when the app is in Background. Behaviour in Android - Scanning is working when the app is in the minimised state but not working when the app is in a killed state/when the phone is locked. Behaviour in iOS - Scanning not working when the app is in minimised state and also not working when the app is in a killed state/when the phone is locked. Expected Behaviour - Scanning should work in all the states of the app life cycle. Plugin used - flutter_blue_plus,Workmanager.

Tried giving all the background permissions and using workmanager but scanning only works when the app is foreground or in the minimised state in Android and only in the foreground state in ios. Expected Behaviour - Scanning should work in all the states of the app life cycle.

Cavin Macwan
  • 1,183
  • 5
  • 12
rahul goti
  • 11
  • 4
  • Possible duplicate of: https://stackoverflow.com/questions/26604177/bluetooth-le-device-scan-in-background-from-ios (it's not quite clear all your symptoms) See also https://stackoverflow.com/questions/48765739/bluetooth-le-ios-unable-to-scan-in-background – Rob Napier May 14 '23 at 15:45

1 Answers1

1

"Tried giving all the background permissions." In iOS, does that include the bluetooth-central mode (that's the only one you need for this)? Note that iOS will not "re-discover" devices in the background, even if you request duplicates. It will only discover them a single time per scan, and you must scan for a specific set of service UUIDs (not "all services" or nil).

Note that if the app is killed by the user on iOS, you should not expect scanning to continue (though I have encountered cases where it does, so do not assume that there is any promise here). The user in that case has explicitly disabled your app. It is possible to reawaken killed apps with silent push notifications if the user allows it. If the app is killed by the system (to recover system resources), you generally should expect scanning to continue on the app's behalf, and the app to be relaunched if a new device is discovered.

For Android, see https://stackoverflow.com/a/44291991/97337 and make sure you're enabling ACCESS_COARSE_LOCATION.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610