gpt4 book ai didi

ios - CLLocationManager didUpdateToLocation :, 在哪个线程上?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:09:50 25 4
gpt4 key购买 nike

我目前正尝试在 CLLocationManager 委托(delegate)调用上实现超时功能。这是代码:

- (void)checkInAt:(UALocation *)location timeout:(NSTimeInterval)timeout {
NSDate *tickDate = [NSDate dateWithTimeIntervalSinceNow:timeout];
self.locationManager = [[CLLocationManager alloc] init];

self.timeout = [[NSTimer alloc] initWithFireDate:tickDate interval:0 target:self selector:@selector(timedOut:) userInfo:nil repeats:NO];
[self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
@synchronized (self.timeout) {
// Todo what if the timer fires right now?
// Is it even feasible? On what thread is CLLocationManager operating?
if (self.timeout.isValid) {
[self.timeout invalidate];
}
else {
// Timed out
return;
}
}

[manager stopUpdatingLocation];
// Do the actual check in
}

- (void)timedOut:(NSTimer *)timer {
@synchronized (timer) {
if (!timer.isValid) {
return;
}
}
}

如果您阅读了代码,您可能已经无意中发现了我的问题。

  1. 是否有更好的方法(= CLLocationManager 中已经存在)来实现这样的超时?
  2. CLLocationManager 在哪个线程上调用其委托(delegate)的方法?
  3. 如果它不是主线程,我可能会遇到注释突出显示它的问题。我怎样才能避免这种情况?

最佳答案

您可以简单地在方法中添加断点,然后在 xcode 的左侧您将看到哪个线程。

第一个线程为主线程

enter image description here

关于ios - CLLocationManager didUpdateToLocation :, 在哪个线程上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17022607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com