- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我们的应用中,我使用 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/
我想接收位置更新。我已将位置委托(delegate)添加到 header : @interface AppDelegate : UIResponder 以及以下功能: - (BOOL)applica
我以这种方式初始化locationManager: if (!self.locManager) { self.locManager = [[CLLocationManager alloc] i
我正在尝试为我的用户找到准确的纬度/经度坐标。我引用了文档并找到了 LocateMe 示例项目。我正在尝试编辑代码,以便弹出警报,让用户知道位置信息是否准确。 我有下面的代码,但警报总是说用户的位置信
我想接收位置更新。我已经在头文件中添加了一个位置委托(delegate),但是 didUpdateToLocation 方法没有触发我的代码是 @interface FirstViewControll
我正在使用模拟器和我的设备对此进行测试,但无论我做什么,都不会调用 didUpdateToLocation。我试过更改我在 sim 卡中的位置,关闭然后再次打开我手机上的定位服务以强制手机搜索新位置…
您好,即使应用程序在后台运行,我也想获取用户的位置,然后我想将该信息上传到数据库,当用户再次运行该应用程序时,它会向他显示他访问过的所有地点。所以我读了这篇文章 https://www.raywend
在我们的应用中,我使用 CoreLocation 来获取用户的位置。我认为对 startUpdatingLocation 的调用每次都会调用 locationManager:didUpdateLoca
我有一个应用程序,用户在慢跑或骑自行车时跟踪他/她的路线,所以我需要完美的位置,所以用户的路线将是完美的。 但是,我有一个问题, locManager = [[CLLocationManager al
我使用这段代码来获取经度和纬度。 (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLL
下面的方法 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLoca
同时支持 iOS 5 和 6,应从 didUpdateToLocation 调用 didUpdateLocations。 如何进行调用并构建 Locations 数组?有代码示例吗? 谢谢。 最佳答案
我正在创建一个使用核心位置的应用程序,这是我的代码: .h : #import #import @interface ViewController : UIViewController
我正在尝试从 didUpdateToLocation 方法调用一个方法,如下所示。在我的 buttonUpdate 方法中,我正在更新界面,并试图避免如果我将代码块直接放在 didUpdateToLo
这个问题在这里已经有了答案: Get Location Updates for iOS App Even when Suspended (2 个答案) 关闭 5 年前。
我目前正尝试在 CLLocationManager 委托(delegate)调用上实现超时功能。这是代码: - (void)checkInAt:(UALocation *)location timeo
我有一个 iOS 应用程序使用用户的当前位置。我这样做: -(void)startGeoloc{ NSLog(@"start geoloc"); locationManager = [
我正在尝试记录用户随时间的位置。如果用户在移动它工作正常并且委托(delegate)方法 didUpdateToLocation 被可靠地调用。但是如果用户是静止的并且应用程序在后台运行然后一段时间后
花了几天时间试图解决这个问题,但找不到任何有效的解决方案。我检查了 stackoverflow 上的所有帖子并尝试了他们所有的解决方案,但似乎没有任何效果。我还尝试了 CLLocation 的苹果测试
随着 iOS6 的发布,Apple 希望我们使用 didUpdateLocations 而不是 didUpdateToLocation。谁能解释一下如何正确使用 didUpdateLocations?
我知道 iPhone 模拟器默认位于美国的某个位置,但这是否意味着 didUpdateToLocation 永远不会被调用?所有被调用的是didFailWithError,这也是在很长一段时间之后。调
我是一名优秀的程序员,十分优秀!