2013-05-06 21 views
0

我想了很多事情阻止我的應用程序的位置更新,但似乎沒有工作...位置後的LocationManager =零仍然監測和stopUpdatingLocation稱爲

我做什麼(職位的方面: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更新?

我當然錯過了一些東西,但我沒有得到什麼:/。

感謝您的想法和幫助。

+0

//初始化我的locationManager並開始監控: locationManager = [[CLLocationManager alloc] init]; [locationManager startUpdatingLocation]; // ..使用locationManager給我的座標的一些代碼。 //停止監測: locationManager = nil; 這一切都在一個方法?那會是錯誤的。 – tzl 2013-05-06 15:15:39

+0

是的,它是..?怎麼了 ? :/ – Lucien 2013-05-06 16:47:36

+0

,因爲位置管理器已分配零。您將無法在回調locationManager中訪問它:didUpdateLocations:如果您在回調中放置了[locationManager stopUpdatingLocation],它將不起作用。 – tzl 2013-05-07 02:32:22

回答

4

一種可能性:在地圖上移動的藍點是因爲您將MKMapView的showsUserLocation設置爲YES。它會跟蹤,直到您將其設置爲NO。

另一種可能性:此行是錯誤的:

locationManager = nil; 

那請問停止監控,但它確實導致你無法參照位置管理,所以現在你不能停止監控!切斷那條線。

+0

感謝您的回答。但我認爲'showsUserLocation'只是MKMapView的藍點的「顯示」屬性,所以對我而言,並不意味着位置監視已停止。所以對我來說,將'showsUserLocation'設置爲NO不會停止後臺監控任務。我錯了 ? 而我不明白爲什麼藍點仍然移動,如果位置不更新:)。由於沒有更新座標值,位置應該保持不變。我又錯了? – Lucien 2013-05-06 16:42:14

+0

閱讀文檔。 「*只要此屬性爲YES *,地圖視圖*就會定期跟蹤用戶的位置*和*更新*。 – matt 2013-05-06 16:51:06

+0

好吧,我的壞...感謝您的答案。 – Lucien 2013-05-06 17:20:23

0

我面對,即使在我放置代碼

[locationManager stopUpdatingLocation]; 
locationManager=nil; 

我的應用程序是使用這是未必然消耗電池功率GPS服務同樣的問題。此問題的解決方案是關閉MKMapView的showUserLocation屬性。

[self.mapView setShowsUserLocation:NO]; 

由於的MKMapView不斷使用GPS service即使LocationManager是零。

希望它會幫助你

0

使用此代碼行

[self.locationManager stopUpdatingLocation]; 
self.locationManager.delegate = nil; 
self.locationManager = nil; 

謝謝!

相關問題