繁体   English   中英

CoreLocation 非 iBeacon 蓝牙设备扫描

[英]CoreLocation Non-iBeacon Bluetooth device scan

我想查找蓝牙设备并使用特定时间段获取 RSSI 值。 我可以扫描 iBeacons。 但我也想找到其他蓝牙设备(如 iPhone 设备)。 如何使用 CoreLocation 扫描所有设备?

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if status == .authorizedAlways {
            if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
                if CLLocationManager.isRangingAvailable() {
                    startScanning()
                }
            }
        }
    }

    func startScanning() {
        let uuid = UUID(uuidString: "XXXXX")!
        let beaconRegion = CLBeaconRegion(proximityUUID: uuid, major: 0, minor: 0, identifier: "XXXXX")

        locationManager.startMonitoring(for: beaconRegion)
        locationManager.startRangingBeacons(in: beaconRegion)
    }

    func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
        extendBackgroundRunningTime()
        if beacons.count > 0 {
            print(beacons)
            updateDistance(beacons[0].proximity)
        } else {
            updateDistance(.unknown)
        }
    }

您无法使用此方法扫描蓝牙设备。您只能使用 Core Bluetooth Frame 扫描蓝牙设备。 Go 通过以下蓝牙教程。 按这里获取链接

暂无
暂无

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

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