Swift中startMonitoringForRegion之后的RequestStateForRegion [英] RequestStateForRegion after startMonitoringForRegion in Swift

查看:98
本文介绍了Swift中startMonitoringForRegion之后的RequestStateForRegion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始监视类似区域时

When I start monitoring a region like

locationManager.startMonitoringForRegion(tGeoFence[wert][wert2])

,然后尝试确定是否已经输入,就像这样:

and try to determine if it is already entered right after that like this:

for region in locationManager.monitoredRegions {
    if let cireg = region as? CLCircularRegion {
        if cireg.identifier == tGeoFence[wert][wert2].identifier {
            locationManager.requestStateForRegion(cireg)
        }
    }
}

不起作用,导致在执行代码的第二部分时该区域的注册未完成.延迟执行该部分似乎很难( diddeterminestate并不总是被调用),有没有更好的方法解决这个问题?

doesn't work, cause the registration of the region is not finished when the 2nd part of the code is executed. Delaying the execution of that part seems ugly (diddeterminestate not always called), is there a better way to solve this?

推荐答案

发现,显然 didStartMonitoringForRegion 委托函数是要求 requestStateForRegion 的正确位置:

Found out, obviously the didStartMonitoringForRegion delegate function is the right place to ask for requestStateForRegion:

func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
    locationManager.requestStateForRegion(region)   
}

糟糕的是,我仍然需要短暂的延迟,或者有时不调用 requestStateForRegion :

Awful thing is, I still need a short delay or sometimes requestStateForRegion is not called:

func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
        self.locationManager.requestStateForRegion(region)
    }
}

:(

这篇关于Swift中startMonitoringForRegion之后的RequestStateForRegion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆