gpt4 book ai didi

iphone - 在 locationManager = nil 和 stopUpdatingLocation 调用后位置仍在监控

转载 作者:行者123 更新时间:2023-11-28 19:10:11 25 4
gpt4 key购买 nike

我尝试了很多方法来停止我的应用程序的位置更新,但似乎没有任何效果......

我做什么(关于帖子: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/

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