简体   繁体   English

在没有iBeacon的情况下实现地理围栏时,当应用未运行时,didEnterRegion和didDetermineState不被调用

[英]didEnterRegion & didDetermineState not being called when the app is not running while implementing Geofencing without iBeacon

I am trying to implement Geofencing with out iBeacon. 我正在尝试使用iBeacon实施Geofencing。 The didStartMonitoringFor is getting called, but didEnterRegion & didDetermineState not being called when the app is not running. didStartMonitoringFor获取调用,但didEnterRegiondidDetermineState当应用程序没有运行不会被调用。

I am calling the requestState in didStartMonitoringFor . 我在didStartMonitoringFor调用requestState So the didDetermineState is being called for the first time. 因此, didDetermineState是第一次被调用。 But not getting called while location changes. 但是在位置更改时不会被呼叫。 Can some one help me ? 有人能帮我吗 ?

Thanks in advance ! 提前致谢 !

Thank God ! 感谢上帝 ! I got the answer by myself. 我一个人得到答案。

I have been doing all declaration and delegate method implementation in Home screen classs. 我一直在执行主屏幕类中的所有声明和委托方法实现。 I changed all part to AppDelegate class. 我将所有部分都更改为AppDelegate类。 Also made some changes to properties for location manager as 还对位置管理器的属性进行了一些更改,例如

    locationManager.delegate = self
    locationManager.activityType = .automotiveNavigation
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    locationManager.distanceFilter = 10.0
    locationManager.requestAlwaysAuthorization() 

Also implemented both delegate methods 还实现了两种委托方法

func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
    manager.requestState(for: region)
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
    if state == .inside
    {
            addNotification(region: region)
    }
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
            addNotification(region: region)
    }

And it worked ! 而且有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM