简体   繁体   English

iOS BLE scanForPeripheralsWithServices:options:在背景上

[英]IOS BLE scanForPeripheralsWithServices:options: on Background

CentralManager doesn't scan BLE device on Background.... CentralManager不会在后台扫描BLE设备。

I already set UIBackgroundModes , bluetooth-central in info.plist. 我已经在info.plist中设置了UIBackgroundModesbluetooth-central )。

also tried input UUID for service like this.. 还尝试输入UUID这样的服务。

[CentralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:@"0xFFA0"]] options:nil];

(0xFFA0 is UUID for Service.) (0xFFA0是用于服务的UUID。)

also tried "C337FA9-4DCF-****-77AB-************"; 还尝试了"C337FA9-4DCF-****-77AB-************"; UUID for device. 设备的UUID。 whatever I put the UUID in Services. 无论我将UUID放入“服务”中。 not found any device on Background. 在后台找不到任何设备。

when foreground.. scanForPeripheralsWithServices:nil found all devices. 当前景.. scanForPeripheralsWithServices:nil找到所有设备时。 but not scanForPeripheralsWithServices:someuuids 但不是scanForPeripheralsWithServices:someuuids

can anyone help me? 谁能帮我?

1.if you use 1.如果您使用

scanForPeripheralsWithServices:someuuids

There must be some device advertise bluetooth packets with this uuids.This can work well in both foreground and backgournd 必须有一些设备使用此uuid来宣传蓝牙数据包。这可以在前景和后景中很好地工作

2 if you use 2,如果您使用

scanForPeripheralsWithServices:nil

You can get all device you want ,but this does not work when in background. 您可以获取所需的所有设备,但是在后台运行时不起作用。

So,if you want to get result in background,you have to set your Peripherals advertise BLE packets with UUID. 因此,如果要在后台获取结果,则必须设置外围设备使用UUID通告BLE数据包。

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

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