gpt4 book ai didi

ios - 没有第二次调用 didUpdateToLocation

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

在我们的应用中,我使用 CoreLocation 来获取用户的位置。我认为对 startUpdatingLocation 的调用每次都会调用 locationManager:didUpdateLocations。但是一旦第一次被调用,他们就再也不会被调用了。

在我的 AppDelegate.m 中:

- (void) startStandardUpdates {
if (_locationManager == nil) {
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = 10;
[_locationManager startUpdatingLocation];

} else {
NSLog(@"[LOCATION]: Location Manager already exists.");
[_locationManager startUpdatingLocation];
}
}

然后通过NSTimer调用:

- (void) startTask {
NSLog(@"Start task called.");
[NSTimer scheduledTimerWithTimeInterval:15
target:self
selector:@selector(actualTask)
userInfo:nil
repeats:YES];
}

- (void) actualTask {
NSLog(@"[TASK]: Starting location service...");
[self startStandardUpdates];
}

上面的代码应该每 15 秒调用一次 startUpdatingLocation 但 didUpdateToLocation 方法不会被第二次调用(第一次成功调用...)。

有没有办法“以编程方式”调用(或强制)didUpdateToLocation?或者我们必须等到 didUpdateToLocation 获取位置?我已经搜索了每 x 分钟/秒获取用户位置的方法,但似乎没有人成功实现这一目标。我想做的只是等同于 Android 如何使用服务类(iOS 没有这个)。

如有任何帮助,我们将不胜感激。
谢谢。

最佳答案

_locationManager.distanceFilter=10;您的距离过滤器设置为 10 米,您将不会收到通知。一旦位置移动到足以超过您的距离过滤器设置,您将收到一个 didUpdateToLocation 回调...

关于ios - 没有第二次调用 didUpdateToLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13898185/

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