【发布时间】:2011-12-12 04:11:39
【问题描述】:
我想在我的应用中搜索当前位置,但我看到整个位置服务都不允许。
@interface LoginViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager* locationManager;
CLLocation* currentLocation;
} //header file
//implementation header file
(void)loginButtonPressed:(id)aSender
{
if (locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
}
[locationManager startUpdatingLocation];
}
//implementation CLLocationManagerDelegate
(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"update location");
if(self.currentLocation == nil)
{
self.currentLocation = newLocation;
[locationManager stopUpdatingLocation];
}
}
(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"fail with error");
[locationManager stopUpdatingLocation];
self.currentLocation = nil;
}
locationManager调用startUpdatingLocation时(假设不允许定位服务),locationManager无法获取当前位置,调用didFailWithError: method。
在我的情况下,locationManager 在 iOS5 上什么都不调用,但在 iOS4 上调用 didFailWithError: method。我不知道是我的错。
【问题讨论】:
标签: core-location