Hi, all.
I want to range beacons.
I have iBeacons, but didRangeBeacon method’s beacons: [CLBeacon] count is 0.
Please help me.
My code is below.
(swift 3.0, xcode 8.1)
class BeaconListViewController: UIViewController {
private let manager = ESTBeaconManager()
let beaconRegion = CLBeaconRegion(proximityUUID: UUID(uuidString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!, identifier: "ranged region")
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.requestAlwaysAuthorization()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
manager.startRangingBeacons(in: beaconRegion)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
manager.stopRangingBeacons(in: beaconRegion)
}
}
extension BeaconListViewController: ESTBeaconManagerDelegate {
func beaconManager(_ manager: Any, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
if beacons.count == 0 {
print("not found")
} else {
beacons.forEach({ (beacon: CLBeacon) in
print("beacon major, minor, rssi = %@, %@, %d", beacon.major.stringValue, beacon.minor.stringValue, beacon.rssi)
})
}
}
}