iOS 6 CoreLocation不起作用

我做了一个位置应用程序。 但核心位置不起作用。 我在iPhone上测试了其他iPhone应用程序。
像谷歌地球,导航软件。 其他应用程序也不起作用。
为什么不更新位置?
为什么’locationManager:didUpdateToLocation:fromLocation:’消息只调用2次?

也许……我的iPhone崩溃了? 或iOS 6 CoreLocation框架有一些错误?

位置服务 – 开启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); } 

在iOS 6中,Apple通过实施AutoPause API对Core Location进行了重大更改。 当应用程序进入后台时,AutoPause API会暂停位置更新并应用于几个条件(即用户不移动,没有位置修复,用户中断活动)。 为了准确处理暂停事件Apple请求帮助更好地预测是否暂停位置更新设置活动类型(即导航,健身,其他)。 在针对iOS 6编译应用程序时,默认情况下会启用AutoPause API。

简单的解决方法是暂时禁用AutoPause API,始终将’pausesLocationUpdatesAutomatically’设置为NO。 即使应用程序在后台运行,也会发送位置更新,就像以前在

更多细节在这里:

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation delegate不再存在于ios 6中。

而是使用

 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations 

查看Apple文档以获取startUpdateLocation

此代码(以及pausesLocationUpdatesAutomatically)仅在XCode 4.5中编译(其中基本SDK为6)。

如果您想要定位6.0之前的iOS版本,请使用此宏

 #define IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 

以及创建CLLocationManager对象的任何位置

 if(IOS_VERSION_GREATER_THAN_OR_EQUAL_TO (@"6.0")) { locationManagerObj.pausesLocationUpdatesAutomatically = NO; } 

从Xcode 4.5编译时,locationManager委托应该适用于所有版本

你有来自委托方法的任何消息吗?

如果没有消息,请检查您的类的接口描述。

@interface … <... CLLocationManagerDelegate ...>