我尝试了很多方法来停止我的应用程序的位置更新,但似乎没有任何效果......
我做什么(关于帖子: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;
之前,但是给我位置的蓝点仍在移动在这两种情况下都在我的 map 上……
我还设置了一个计时器,它在控制台中打印 locationManager
对象,它给我 (null)
同时蓝点仍在我的 iPhone 5 上移动,所以我不明白……
或者也许点因为另一件事仍在移动,但不是因为 locationManager 更新?
我当然遗漏了一些东西,但我没有得到什么:/。
感谢您的想法和帮助。
最佳答案
一种可能性: map 上移动的蓝点是因为您将 MKMapView 的 showsUserLocation
设置为 YES。它会一直跟踪,直到您将其设置为 NO。
另一种可能:这一行是错误的:
locationManager = nil;
那不会停止监控,但它确实导致您无法引用位置管理器,所以现在您不能 停止监控!剪掉那条线。
关于iphone - 在 locationManager = nil 和 stopUpdatingLocation 调用后位置仍在监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16401743/