简体   繁体   English

iBeacon iOS 10:设备可以扫描并从其他外围设备接收广告吗?

[英]iBeacon iOS 10: Can device scan for and receive advertisements from other peripheral devices?

brand new here. 这里是全新的。

The Tl;dr: Can an iOS device advertise a CB advertisement (CBAdvertisementDataServiceUUIDsKey and/or CBAdvertisementDataLocalNameKey) that can be scanned for by another iOS device? Tl; dr:iOS设备可以播发可以被其他iOS设备扫描的CB广告(CBAdvertisementDataServiceUUIDsKey和/或CBAdvertisementDataLocalNameKey)吗?

I believe my question is fresh based on deprecations and changes to CoreBluetooth and CoreLocation in the later versions of iOS. 我相信我的问题是基于不赞成使用的内容以及在更高版本的iOS中对CoreBluetooth和CoreLocation的更改而引起的。 Also, for now, I'm only referring to "foreground" ops. 另外,就目前而言,我仅指“前景”操作。

From what I have read and tested, a peripheral can transmit a Beacon Region (unique Proximity UUID, major and minor (but notably without the "identifier")) using CL. 根据我的阅读和测试,外围设备可以使用CL传输信标区域(唯一接近UUID,主要和次要(但特别是没有“标识符”))。 And with CB, a peripheral can also "advertise" either of two small additional amounts of data: CBAdvertisementDataServiceUUIDsKey and CBAdvertisementDataLocalNameKey. 借助CB,外围设备还可以“公告”两个额外的少量数据之一:CBAdvertisementDataServiceUUIDsKey和CBAdvertisementDataLocalNameKey。

What I've not been able to achieve is having the device (eg iPhone) scan using CB for either of these additional keys, nor as I mentioned the optional "identifier" using either CL or CB. 我无法实现的是让设备(例如iPhone)使用CB扫描这些附加密钥中的任何一个,或者正如我提到的使用CL或CB的可选“标识符”进行扫描。

The only option to specify a scan requires a CBUUID, but an undiscovered iOS peripheral cannot technically advertise that: 指定扫描的唯一选项需要CBUUID,但未发现的iOS外围设备在技术上无法发布该信息:

central.scanForPeripherals(withServices: [CBUUID]?, options: [String : Any]?)

It seems the following would work but it doesn't seem the advertisementData includes the keys above, even as [String : Any]: 似乎下面的方法可以工作,但advertData似乎不包含上述键,即使[String:Any]也是如此:

func centralManager(_ central: CBCentralManager,
                             didDiscover peripheral: CBPeripheral,
                             advertisementData: [String : Any],
                             rssi RSSI: NSNumber){
//code
}

Any help/answers here would be appreciated. 这里的任何帮助/答案将不胜感激。 Thanks! 谢谢!

Unfortunately iOS is pretty unhelpful here. 不幸的是, iOS在这里毫无帮助。 Apple locks down CoreBluetooth in a number of ways. 苹果通过多种方式锁定CoreBluetooth。

There are three basic ways of sending/receiving advertisements: 发送/接收广告的三种基本方式:

iBeacon iBeacon显示

  • You can scan for iBeacon advertisements using CoreLocation in the foreground and background, with quick responses, but data fields are limited to ProximityUUID, major and minor. 您可以在前台和后台使用CoreLocation扫描iBeacon广告,并具有快速响应,但是数据字段仅限于ProximityUUID(主要和次要)。

  • You can transmit iBeacon advertisements using CoreBluetooth in the foreground only. 您只能在前台使用CoreBluetooth传输iBeacon广告。

Bluetooth LE Service Advertisements 蓝牙LE服务广告

  • You can transmit these in the foreground (but not the background) using CoreBluetooth, but you cannot attach arbitrary data. 您可以使用CoreBluetooth在前台(但不能在后台)传输这些文件,但不能附加任意数据。 You can, however, send an arbitrary service UUID of 16 bytes. 但是,您可以发送16字节的任意服务UUID。

  • You can scan for service advertisements with CoreBluetooth in the foreground and background and read the service UUID with quick foreground responses and slow background responses. 您可以在前台和后台使用CoreBluetooth扫描服务广告,并读取具有快速前台响应和慢速后台响应的服务UUID。 You can also read attached data from these advertisements up to 18 bytes if using a 16 bit service UUID. 如果使用16位服务UUID,则还可以从这些广告中读取最多18个字节的附件数据。 Eddystone works this way. 涡流以这种方式工作。

Bluetooth LE Manufacturer Advertisements 蓝牙LE制造商广告

  • You cannot advertise manufacturer advertisements at all using CoreBluetooth on iOS, except for the special iBeacon advertisement as described above. 除了如上所述的特殊iBeacon广告,您根本无法在iOS上使用CoreBluetooth来广告制造商广告。

  • You can scan for manufacturer advertisements using CoreBluetooth and you can read attached data, up to 23 bytes. 您可以使用CoreBluetooth扫描制造商的广告,并且可以读取最多23个字节的附件数据。 You cannot detect in the background at all, but foreground detections are quick. 您根本无法在后台进行检测,但是前景检测很快。

Bottom line: if you want to send advertisement data from one iOS device to another in the foreground or background, iBeacon is the only way. 底线:如果要将广告数据从一台iOS设备发送到前台或后台的另一台设备,则只有iBeacon。

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

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