我做一个位置的应用程序。 但核心位置不起作用。 我在我的iPhone测试的其他iPhone应用程序。
像谷歌地球,导航软件。 其他应用程序不还正常工作。
为什么不更新的位置?
为什么 '的LocationManager:didUpdateToLocation:fromLocation:' 所谓的只有2次消息?
也许......我的iPhone打破? 或iOS 6 CoreLocation框架有一些bug?
位置服务 - 在iPhone上设置
的Info.plist
- 的ARMv7
- 加速度计
- 位置服务
- 全球定位系统
- 麦克风
- 磁力仪
代码示例:
- (CLLocationManager *)setupLocationManager
{
if ([CLLocationManager locationServicesEnabled] && [CLLocationManager headingAvailable]) {
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = kCLHeadingFilterNone;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
return locationManager;
}
return nil;
}
- (CLLocationManager *)locationManager
{
switch([CLLocationManager authorizationStatus])
{
case kCLAuthorizationStatusAuthorized:
_deltaTimeLocationReceived = 0.0;
if (_locationManager == nil)
_locationManager = [self setupLocationManager];
return _locationManager;
case kCLAuthorizationStatusDenied:
case kCLAuthorizationStatusRestricted:
if (_locationManager)
_locationManager = nil;
return _locationManager;
case kCLAuthorizationStatusNotDetermined:
_deltaTimeLocationReceived = 0.0;
if (_locationManager == nil)
_locationManager = [self setupLocationManager];
return nil;
}
return nil;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), newLocation.description);
if (self.locationManager) _locationSignal++;
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), error.description);
}