Just purchased an estimote development pack but the functionality with iOS 10.x appears to be broken for the past six months or more.
I configured everything to the book.
Region monitoring works.
Ranging fires once and then dies!
Tried the code on an iPad Air and an iPhone 5S, both behave in the same way.
Tried out the development portal; two example using your proximity library work… but I wait I want to know if I am immediate, near, far or in unknown here; as in Apple terminology? Will Estimote beacons work with the apple SDK? If not, how does this work if I have a mixture of beacons in use? We previously had radBeacons, which worked with the AppleSDK last time I checked.
Ok I found it! I was registering the same region twice! That was it, simply that. Here the sample code I used to find/test it ultimately. This works… credit needs to go to “Hacking with Swift” where the 90% of this code comes from.
import CoreLocation
import UIKit
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var distanceReading: UILabel!
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
view.backgroundColor = UIColor.gray
let b2S:beaconsT = beaconsT(bUUID: "B9407F30-F5F8-466E-AFF9-XXXX",bMajor: 54360,bMinor: 60020,bID: "beetroot")
let b3S:beaconsT = beaconsT(bUUID: "5A4BCFCE-174E-4BAC-A814-XXXX",bMajor: 123,bMinor: 456,bID: "lemon")
beacons2G.append(b2S)
beacons2G.append(b3S)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedAlways {
if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
if CLLocationManager.isRangingAvailable() {
startScanning()
}
}
}
}
struct beaconsT {
var bUUID:String
var bMajor: CLBeaconMajorValue
var bMinor: CLBeaconMinorValue
var bID: String
}
var beacons2G:[beaconsT] = []
func startScanning() {
// let uuid = UUID(uuidString: "5A4BCFCE-174E-4BAC-A814-092E77999999")!
// let beaconRegion = CLBeaconRegion(proximityUUID: uuid, major: 123, minor: 456, identifier: "MyBeacon")
for b2D in beacons2G {
let uuid = UUID(uuidString: b2D.bUUID)!
let beaconRegion = CLBeaconRegion(proximityUUID: uuid, major: b2D.bMajor, minor: b2D.bMinor, identifier: b2D.bID)
locationManager.startMonitoring(for: beaconRegion)
locationManager.startRangingBeacons(in: beaconRegion)
}
}
func update(distance: CLProximity) {
UIView.animate(withDuration: 0.8) { [unowned self] in
switch distance {
case .unknown:
self.view.backgroundColor = UIColor.gray
self.distanceReading.text = "UNKNOWN"
case .far:
self.view.backgroundColor = UIColor.blue
self.distanceReading.text = "FAR"
case .near:
self.view.backgroundColor = UIColor.orange
self.distanceReading.text = "NEAR"
case .immediate:
self.view.backgroundColor = UIColor.red
self.distanceReading.text = "RIGHT HERE"
}
}
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
if beacons.count > 0 {
let beacon = beacons.first
update(distance: (beacon?.proximity)!)
} else {
update(distance: .unknown)
}
}
}