如何获取 BLE 广告数据 Swift 2

Posted

技术标签:

【中文标题】如何获取 BLE 广告数据 Swift 2【英文标题】:How to get BLE Advertisement Data Swift 2 【发布时间】:2016-01-21 12:26:08 【问题描述】:

我正在尝试扫描信标附近并从中获取信息。现在我得到了一些像 uuid,major-minor 值,但我也不想读取广告数据。有我的代码,我该如何处理?

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion)
    
        // Tells the delegate that one or more beacons are in range.
        let foundBeacons = beacons
        if foundBeacons.count > 0        
            if let closestBeacon = foundBeacons[0] as? CLBeacon 
                var proximityMessage: String!
                    let makeString = "Beacon Details:\n"
                    let uuid = "UUID = \(closestBeacon.proximityUUID.UUIDString)\n"
                    let identifier = "Identifier = \(region.identifier)\n"
                    let major = "Major Value = \(closestBeacon.major.intValue)\n"
                    let minor = "Minor Value = \(closestBeacon.minor.intValue)\n"
                    let distance = "Distance From iBeacon = \(proximityMessage)"

                    self.beaconStatus.text = makeString
                    self.uuidStatus.text=uuid
                    self.distanceStatus.text=distance
                
            
        
    

【问题讨论】:

【参考方案1】:

很遗憾,您无法在 iOS 中访问 iBeacon 广告的原始广告数据。对于任何匹配 iBeacon 格式的蓝牙广告包,Apple 会主动阻止对蓝牙广告数据的访问。

这意味着 ProximityUUID、major 和 minor 都是您可以读取的。

更多详情请见here。

【讨论】:

这个信息真的很有用,但我很困惑。在这个示例中我可以读取广告数据github.com/Ladvien/bleModule/blob/master/bleModule/… 有什么区别我如何在我的代码上实现它? 使用该样本,您只能读取非 iBeacon 广告的广告数据 好吧,比最后一个问题如何实现这个功能来读取非信标广告的广告数据

以上是关于如何获取 BLE 广告数据 Swift 2的主要内容,如果未能解决你的问题,请参考以下文章

BLE广告包获取频率变得非常低

如何在android中配置ble广告以供ios检测

如何在 Android 中获取当前连接的 BLE 外围设备

在 Swift 中的 iOS BLE 扫描中提取广告数据 [kCBAdvDataManufacturer] 的内容

如何传递额外的广告 BLE 数据?

(java, bluetooth-low energy, ble) 如何通过 BLE 从 android 设备获取数据