简体   繁体   English

当手机处于睡眠模式时,iOS BLE在后台扫描广告数据

[英]iOS BLE Scanning for AdvertisementData in background when the phone is in Sleep Mode

I'm trying to search if it is possible for iPhone to scan BLE device and read its advertisementData while it is in sleep mode. 我正在尝试搜索iPhone是否有可能在处于睡眠模式时扫描BLE设备并读取其advertData。

For example, continuous scanning as long as it takes and then if a device changes its advertisementData the phone will wake up and fire a local notification. 例如,只要进行扫描,就会持续扫描,然后如果设备更改了adsData,则电话将唤醒并触发本地通知。 Meaning, the app is running in background mode for x period of time. 这意味着该应用程序在后台模式下运行了x个时间段。

Is it possible? 可能吗? Because in android it is. 因为在android中是。

There are restrictions on peripheral scanning when your app is running in the background: 当您的应用在后台运行时,外围扫描有一些限制:

  • You must specify the service UUIDs you are interested in; 您必须指定您感兴趣的服务UUID。 you cannot use nil 你不能用nil
  • The duplicate scan option key is not supported. 不支持重复扫描选项密钥。 This is probably what is preventing you from achieving your desired result 这可能是导致您无法获得预期结果的原因

As the duplicates key is ignored in the background, if a peripheral has previously been discovered by your app then its discovery will not re-trigger the didDiscoverPeripheral delegate method until your app is re-started. 由于重复键在后台被忽略,因此如果您的应用先前已发现外围设备,则其发现将不会重新触发didDiscoverPeripheral委托方法,直到重新启动您的应用为止。

For long-term discovery you should also opt-in to state-restoration but that isn't needed for a simple test-case running under Xcode. 对于长期发现,您还应该选择状态恢复,但这对于在Xcode下运行的简单测试用例而言并不需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM