确定并不总是被称为 [英] diddeterminestate not always called

查看:124
本文介绍了确定并不总是被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有其他人有问题确定并不总是被调用?有时我打电话

  [self.locationManager requestStateForRegion:region]; 

并且没有任何反应。奇怪的是,当我在

中插入一个断点时,

   - (void)locationManager:(CLLocationManager *)manager didDetermineState :( CLRegionState)状态forRegion:(CLRegion *)region 

它开始工作并被调用!这对我来说似乎很不稳定。

解决方案

在监控区域后立即请求区域状态时,我经常遇到这个问题。 / p>

例如

  [self.locationManager startMonitoringForRegion:region]; 
[self.locationManager requestStateForRegion:region];

我确保调用requestStateForRegion调用didDetermineStateForRegion:调用startMonitoringForRegion后不久。现在它不是一个很好的解决方案,它应该小心使用,但它似乎解决了这个烦人的问题。代码如下

  [self.locationManager startMonitoringForRegion:region]; 
[self.locationManager performSelector:@selector(requestStateForRegion :) withObject:region afterDelay:1];


Does anyone else have a problem of having diddeterminestate not always being called? There are sometimes when I call

[self.locationManager requestStateForRegion:region]; 

and nothing happens. The curious thing is that when I insert a break point in

-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

it starts working and being called! It seems very unstable to me.

解决方案

I often experienced this problem when requesting the state of a region right after monitoring it.

e.g.

[self.locationManager startMonitoringForRegion:region];
[self.locationManager requestStateForRegion:region];

I ensured that didDetermineStateForRegion was called by scheduling requestStateForRegion: shortly after calling startMonitoringForRegion. Now it's not a great solution and it should be used carefully but it seemed to fix this annoying issue for me. Code below

[self.locationManager startMonitoringForRegion:region];
[self.locationManager performSelector:@selector(requestStateForRegion:) withObject:region afterDelay:1];

这篇关于确定并不总是被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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