flutter_blue_plus在后台或设备锁定时无法扫描。

huangapple go评论77阅读模式
英文:

flutter_blue_plus not able to scan when in background / when device is locked

问题

无法在应用程序处于后台时扫描设备。
在Android中的行为 -
当应用程序处于最小化状态时,扫描有效,但当应用程序处于killed状态/手机被锁定时,扫描无效。
在iOS中的行为 -
当应用程序处于最小化状态时,扫描无效,同样,当应用程序处于killed状态/手机被锁定时,扫描也无效。
期望的行为 -
扫描应该在应用程序生命周期的所有状态下都有效。
使用的插件 - flutter_blue_plusWorkmanager
尝试授予所有后台权限并使用Workmanager,但在Android中只有在应用程序前台或最小化状态下扫描才有效,在iOS中只有在应用程序前台状态下扫描才有效。
期望的行为 -
扫描应该在应用程序生命周期的所有状态下都有效。

英文:

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.

答案1

得分: 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.

英文:

"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.

huangapple
  • 本文由 发表于 2023年5月13日 10:50:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76240884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定