iOS iBeacon基本操作
示例
设置监控信标
func initiateRegion(ref:BeaconHandler){
let uuid: NSUUID = NSUUID(UUIDString: "<UUID>")
let beacon = CLBeaconRegion(proximityUUID: uuid, identifier: "")
locationManager?.requestAlwaysAuthorization() //分区管理器对象
beacon?.notifyOnEntry = true
beacon?.notifyOnExit = true
beacon?.notifyEntryStateOnDisplay = true
locationManager?.startMonitoringForRegion(beacon!)
locationManager?.delegate = self;
//检查信标监视是否可用于此设备
if (!CLLocationManager.isMonitoringAvailableForClass(CLBeaconRegion)) {
print("error")
}
locationManager!.startRangingBeaconsInRegion(self.beacon!)
}位置经理进入和退出区域
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
if(region.isKindOfClass(CLBeaconRegion)) {
locationManager!.startRangingBeaconsInRegion(self.beacon!)
}
}
func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
if(region.isKindOfClass(CLBeaconRegion)) {
locationManager!.stopRangingBeaconsInRegion(self.beacon!)
}
}位置管理器范围信标
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
print(beacons.first.major)
}
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短