首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在swift中检测到任何iBeacon?

如何在swift中检测到任何iBeacon?
EN

Stack Overflow用户
提问于 2018-03-29 14:11:14
回答 1查看 656关注 0票数 0

有没有办法检测到任何iBeacon?

uuid的一些通配符/小丑

在viewidload中,我有以下代码

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()
    locationManager = CLLocationManager.init()
    locationManager.delegate = self
    locationManager.requestWhenInUseAuthorization()
    startScanningForBeaconRegion(beaconRegion: getBeaconRegion())
}

func getBeaconRegion() -> CLBeaconRegion {
   let beaconRegion : CLBeaconRegion = CLBeaconRegion(proximityUUID: NSUUID.init(uuidString:"11111111-1111-1111-1111-111111111111")! as UUID,
        identifier: "my beacon")
    return beaconRegion
}

func startScanningForBeaconRegion(beaconRegion: CLBeaconRegion) {
    print(beaconRegion)
    locationManager.startMonitoring(for: beaconRegion)
    locationManager.startRangingBeacons(in: beaconRegion)
}

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    print(beacons)
}

将uuid设置为11111确实会使我的应用程序崩溃。有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2018-03-29 16:44:33

关于扫描信标及其区域,您需要知道的第一件事是信标UUID。没有信标UUID,您就不能提前扫描。您提供的代码部分似乎可以用于扫描信标,但正如我所说的,您必须事先知道信标UUID。我认为这篇关于区域定义和扫描的苹果文档可能会对你有用。https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49549143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档