3
我使用CLLocationManager來確定我的當前位置:CLLocationManager沒有在的iOS 4.3模擬器工作
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
self.currentLocation = newLocation;
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (self.currentLocation == nil || self.currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
self.currentLocation = newLocation;
}
[locationManager stopUpdatingLocation];
}
它工作在5.1的iOS模擬器,但不是的iOS 4.3模擬器,我想這可能是一個在iOS 5.1之前的真實設備中出現問題。爲什麼它不起作用?
你能描述一下你的意思嗎?不工作。委託方法根本沒有被調用?也許嘗試設置desiredAccuracy過濾器。檢查授權狀態。實現didFail方法,看看它是否下降到那裏 – Mike 2012-08-16 13:24:57
確保在嘗試使用CCLocationManager之前檢查'[CLLocationManager locationServicesEnabled]',即使在模擬器中,您的位置服務也可以關閉。 – Joe 2012-08-16 13:26:06
我試過「locationServicesEnabled」方法,你是對的喬,位置服務沒有啓用。那麼,我該如何啓用它,或者我該怎麼做? – realuser 2012-08-16 13:36:11