I am putting together a simple estimote test using swift and coreLocation. However I am not getting didEnterRegion, didExitRegion
I read following answers already but it still didn't end my problem.
startMonitoringForRegion never calls didEnterRegion/didExitRegion
locationManager:didEnterRegion not called when a beacon is detected
I added Background modes (Location updates)
I get the "didStartMonitoringForRegion" log in the output but then don't get any didenter or exit. I tried to walk out of house with beacon and back in but no luck. Ranging however works.
var locManager: CLLocationManager = CLLocationManager()
let iceRegion: CLBeaconRegion = CLBeaconRegion(proximityUUID: BEACON_PROXIMITY_UUID, major: BEACON_ICE_MAJOR, identifier: "ice")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if locManager.respondsToSelector("requestAlwaysAuthorization") {
locManager.requestAlwaysAuthorization()
}
if (self.deviceSettingsAreCorrect())
{
iceRegion.notifyOnEntry = true
iceRegion.notifyOnExit = true
iceRegion.notifyEntryStateOnDisplay = true
locManager.delegate = self
locManager.startMonitoringForRegion(iceRegion)
locManager.startRangingBeaconsInRegion(iceRegion)
}
}
func locationManager(manager: CLLocationManager!, didStartMonitoringForRegion region: CLRegion!) {
println("didStartMonitoringForRegion");
locManager.requestStateForRegion(region);
}
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
println("did Enter Region")
}
func locationManager(manager: CLLocationManager!, didExitRegion region: CLRegion!) {
println("did Exit Region")
}
func locationManager(manager: CLLocationManager!, didDetermineState state: CLRegionState, forRegion region: CLRegion!) {
println("didDetermineState \(state)");
switch state {
case .Inside:
println("BeaconManager:didDetermineState CLRegionState.Inside");
case .Outside:
println("BeaconManager:didDetermineState CLRegionState.Outside");
case .Unknown:
println("BeaconManager:didDetermineState CLRegionState.Unknown");
default:
println("BeaconManager:didDetermineState default");
}
}
func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [CLBeacon]!, inRegion region: CLBeaconRegion!) {
println("BM didRangeBeacons");
for beacon: CLBeacon in beacons {
// TODO: better way to unwrap optionals?
if let major: String = beacon.major?.stringValue {
if let minor: String = beacon.minor?.stringValue {
println(major)
}
}
}
}
func deviceSettingsAreCorrect() -> Bool {
var errorMessage = ""
if !CLLocationManager.locationServicesEnabled()
|| (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Denied) {
errorMessage += "Location services are turned off! Please turn them on!\n"
}
if !CLLocationManager.isRangingAvailable() {
errorMessage += "Ranging not available!\n"
}
if !CLLocationManager.isMonitoringAvailableForClass(CLBeaconRegion) {
errorMessage += "Beacon monitoring not supported!\n"
}
let errorLen = countElements(errorMessage)
if errorLen > 0 {
println(errorMessage)
}
return errorLen == 0
}