[英]CoreBluetooth: Range Detection in Background mode
I'm working on an App that connects with a peripheral and needs to watch it's state. 我正在开发一个与外围设备连接并且需要查看其状态的应用程序。
When the App is in foreground range detection is no probleme: I just update the RSSI value from time to time and translate it in a range. 当应用程序处于前景范围时,检测没有问题:我只是不时更新RSSI值,并将其转换为范围。
Now I would like to use the app with a CoreBluetooth Background Mode. 现在我想在CoreBluetooth背景模式下使用该应用程序。 I want to send the user a notification when the device is out of a certain range.
当设备超出一定范围时,我想向用户发送通知。
How can I achieve this behavior? 我该如何实现这种行为?
You can start ranging your peripheral from AppDelegate.m, right after your application start on application didFinishLaunchingWithOptions:
, set the delegate to self, and notify yourself using UILocalNotification
. 您可以在应用程序在
application didFinishLaunchingWithOptions:
上启动application didFinishLaunchingWithOptions:
后立即从AppDelegate.m开始扩展外围设备,将委托设置为self,然后使用UILocalNotification
通知自己。
There's example of it using CoreLocation
instead of CoreBluetooth
here . 有它的例如使用
CoreLocation
代替CoreBluetooth
这里 。
Don't forget to modify your info.Plist
for communicating in background mode. 不要忘记修改您的
info.Plist
以在后台模式下进行通信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.