问题
I wish to keep scanning for Bluetooth Devices and I want app to be alive in the background. Is it possible? It seems like if I have a connected Bluetooth device, and if there is data transfer, then the app stays awake in the background. However, if I am just scanning in the background, it seems like even if I have Uses Bluetooth LE accessories
checked(bluetooth-central
in plist), the app ends up not running.
Is there a way to keep the app alive and continuous scan for devices when it is in the background?
回答1:
If your app is not going to be released on Apple Store, you can use any of the background modes explained here. Please read this whole article if you don't understand background execution in iOS - it's essential that you know this as an iOS developer.
You also seem to not understand fully how Core Bluetooth works in background so please read this article.
In short: you need a good reason to keep your app alive in background indefinitely and be accepted by Apple Store Review.
EDIT:
What OP meant is that the device doesn't get woken up. Solution: You need to listen for particular BLE service in CoreBluetooth in order go get woken up.
来源:https://stackoverflow.com/questions/34117336/ios-bluetooth-background-mode