您的位置:首页 > 移动开发 > IOS开发

iOS 低功耗蓝牙 在后台长期运行的解决方案

2015-09-14 10:57 531 查看


最近一段在做低功耗蓝牙的项目,  有个需求是需要在后台长期运行蓝牙的连接 重连 数据传输等操作,但是苹果对后台运行的程序比较严格,网上现有的很多方案都不合适,后面在苹果文档上找到了答案,完美解决!

就不贴代码了,下面是摘要,看完就懂了:


Performing Long-Term Actions in the Background

Some apps may need to use the Core Bluetooth framework to perform long-term actions in the background. As an example, imagine you are developing a home security app for an iOS device that communicates with a door lock (equipped with Bluetooth low energy technology).
The app and the lock interact to automatically lock the door when the user leaves home and unlock the door when the user returns—all while the app is in the background. When the user leaves home, the iOS device may eventually become out of range of the lock,
causing the connection to the lock to be lost. At this point, the app can simply call the 
connectPeripheral:options:
 method
of the 
CBCentralManager
 class,
and because connection requests do not time out, the iOS device will reconnect when the user returns home.

Now imagine that the user is away from home for a few days. If the app is terminated by the system while the user is away, the app will not be able to reconnect to the lock when the user returns home, and the user may not be able to unlock the door. For apps
like these, it is critical to be able to continue using Core Bluetooth to perform long-term actions, such as monitoring active and pending connections.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息