【发布时间】:2013-05-06 15:11:55
【问题描述】:
我正在尝试很多方法来阻止我的应用的位置更新,但似乎没有任何效果……
我在做什么(关于帖子:StopUpdatingLocation method not working for iOS5):
// Initialise my locationManager and start monitoring :
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
// .. Some code to use the coordinates that locationManager gives me.
// To stop monitoring :
locationManager = nil;
你要知道我在方法中放置了[locationManager stopUpdatingLocation];:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
所以位置只更新了 1 次(顺便告诉我这是否是个好主意……)。
我还尝试在主代码中将 [locationManager stopUpdatingLocation]; 放在 locationManager = nil; 之前,但是在这两种情况下,我的位置的蓝点仍在我的地图上移动……
我还设置了一个计时器,它在控制台中打印locationManager 对象,它给了我(null) 同时我的iPhone 5 上的蓝点仍在移动,所以我不明白...
或者也许点还在移动是因为另一件事,但不是因为 locationManager 更新?
我当然错过了一些东西,但我没有得到什么:/。
感谢您的想法和帮助。
【问题讨论】:
-
// 初始化我的 locationManager 并开始监控: locationManager = [[CLLocationManager alloc] init]; [locationManager startUpdatingLocation]; // .. 一些使用 locationManager 给我的坐标的代码。 // 停止监控:locationManager = nil;所有这一切都在一种方法中吗?那是错误的。
-
是的..?怎么了 ? ://
-
因为位置管理器已经分配为零。您将无法在回调 locationManager:didUpdateLocations: 中再访问它,因此如果您将 [locationManager stopUpdatingLocation] 放在回调中,它将无效。
标签: iphone ios objective-c cllocationmanager