2010-08-16 110 views
3

我使用iPhone SDK 4.0.I已經使用下面的代碼採取現在的位置,但它的委託方法是不是叫自動...我的代碼如下:爲什麼在iOS4.0中不調用委託CurrentLotion的方法(CLLocationManager)?

在.hfile

我有進口

CoreLocation/CoreLocation.h

也委派

CLLocationManagerDelegate

CLLocationManager * locationManager;

在.mfile

locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; 
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m 
[locationManager startUpdatingLocation]; 

,但我不明白的是,當前的位置......我的委託方法是不叫:

  • (無效)的LocationManager (CLLocationManager *)經理 didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
+1

嘗試安裝到iphone上,因爲代碼看起來沒問題。 – mrugen 2011-06-22 05:58:24

回答

0

你的代碼看起來對我來說是正確的。你是否也嘗試在真正的iPhone上運行這些代碼?模擬器並不總是響應位置管理器更新。 還有另一個重要的委託方法,你應該添加到您的.m文件:

 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 

這人會在什麼情況下被稱爲出錯。例如,位置管理器無法定位您的iPhone。

0

我遇到同樣的問題。所有的代碼看起來不錯,但委託方法沒有被調用。

我完全關閉了模擬器。當我重新運行應用程序時,調用了委託方法。

相關問題