美文网首页iOS Developer
iOS设备iBeacon扫描总结

iOS设备iBeacon扫描总结

作者: jackyshan | 来源:发表于2017-03-14 11:14 被阅读790次
image

iBeacon是苹果公司提出的“一种可以让附近手持电子设备检测到的一种新的低功耗、低成本信号传送器”的一套可用于室内定位系统的协议。 这种技术可以使一个智能手机或其他装置在一个iBeacon基站的感应范围内执行相应的命令

1、初始化CLLocationManager和CLBeaconRegion

let locationManager = CLLocationManager()

let beaconRegion: CLBeaconRegion = {
    let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "7B1C1C64-077E-4D23-9F49-7E644A13B5A9")!, identifier: "7B1C1C64-077E-4D23-9F49-7E644A13B5A9")
    region.notifyEntryStateOnDisplay = true
    return region
}()

2、开始扫描

func start() {
    stop()
    
    locationManager.delegate = self
    locationManager.startRangingBeaconsInRegion(beaconRegion)
}

3、实现CLLocationManagerDelegate代理方法

打印授权状态

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .AuthorizedAlways {
        print("Location Access (Always) granted!")
    } else if status == .AuthorizedWhenInUse {
        print("Location Access (When In Use) granted!")
    } else if status == .Denied || status == .Restricted {
        print("Location Access (When In Use) denied!")
    }
}

扫描到设备,accuracy实际距离

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
    print(">>>发现设备: becons: \(beacons)")
    print("------------------------------")
    for bc in beacons {
        print (bc.accuracy)
    }
}

4、停止扫描

func stop() {
    locationManager.stopRangingBeaconsInRegion(beaconRegion)
    locationManager.delegate = nil
    
}

代码参考
https://github.com/jackyshan/bleIbeaconscanner/blob/master/IBeaconScanner.swift

相关文章

  • iOS设备iBeacon扫描总结

    iBeacon是苹果公司提出的“一种可以让附近手持电子设备检测到的一种新的低功耗、低成本信号传送器”的一套可用于室...

  • ibeacon 技术记录

    ibeacon是苹果公司在ios7发布的一款硬件,可以感知ibeacon的位置。ibeacon 只是一个硬件设备,...

  • iBeacon室内定位技术

    项目中用到了ibeacon技术,一直想记录下来,写了一个关于扫描ibeacon设备的Demo,有错误之处,欢迎指正...

  • iOS 中 iBeacon 开发

    iOS 中 iBeacon 开发 iOS 中 iBeacon 开发

  • iBeacon 开发 (一) (iOS设备变成iBeacon设备

    在文章开始先来了解什么是Beacon ? Beacon的标准是什么?Beacon都有哪些使用场景? 什么是Beac...

  • iOS下iBeacon总结

    权限 要使用iBeacon监控,要先做以下检查 检查设备是否支持Beacon扫描 必须获取Always定位权限 且...

  • iOS 中 iBeacon 开发

    iBeacon 介绍 iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其工...

  • iOS 中 iBeacon 开发

    什么是iBeacon? iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其...

  • iOS 中 iBeacon 开发

    什么是iBeacon? iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其...

  • Swift-ibeacon开发

    什么是ibeacon iBeacon是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其工作...

网友评论

    本文标题:iOS设备iBeacon扫描总结

    本文链接:https://www.haomeiwen.com/subject/fpvcnttx.html