swiftcllocationmanagerclregion

LocationManager didEnterRegion not called (again)


I am trying to register regions to be notified when the user enters them. This is the code I use:

public func locationManager(manager:CLLocationManager, didEnterRegion region:CLRegion){
    print("did enter region \(region)")
    let regionPalina=region.identifier;
    if regionPalina==palina{
        regionMonitoringCompletion?()
    }
}

public func locationManager(manager: CLLocationManager, monitoringDidFailForRegion region: CLRegion?, withError error: NSError){
        print(error.localizedDescription)
}

let myLocationManager=CLLocationManager()

func startMonitoringForRegion(completion:(Void->Void)){
    regionMonitoringCompletion=completion;
    myLocationManager.delegate=self
    if !monitoredForRegion{
        myLocationManager.startMonitoringForRegion(self.regionForPalina())
        monitoredForRegion=true
    }
}

public func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion){
    print("region: \(region) registered")
    print(myLocationManager.monitoredRegions)
}

public func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion){
    print("state transition \(state)")
}

func stopMonitoringForRegion(){
    myLocationManager.delegate=nil
    regionMonitoringCompletion=nil
    if !monitoredForRegion {
        myLocationManager.stopMonitoringForRegion(self.regionForPalina())
        monitoredForRegion=false
    }
}

The registration seems to go fine, as didStartMonitoringForRegion is called and it correctly prints the monitoredRegions. Yet neither didEnterRegion, nor didDetermineState and not even monitoringDidFailForRegion are called.

What could be the business?


Solution

  • I ended up simulating the stuff with the user location.