没有调用LocationManager didEnterRegion(再次)

时间:2015-12-10 20:36:06

标签: swift cllocationmanager clregion

我正在尝试注册用户输入时要通知的区域。这是我使用的代码:

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
    }
}

注册似乎没问题,因为调用了StartStonitoringForRegion并正确打印了monitoredRegions。但是,无论是EnterRegion还是didDetermineState都没有调用,甚至还没有监控DDFailForRegion。

可能是什么业务?

1 个答案:

答案 0 :(得分:0)

我最终用用户位置模拟了这些东西。