-->

iOS 6的CoreLocation不起作用(iOS 6 CoreLocation does not

2019-08-01 03:21发布

我做一个位置的应用程序。 但核心位置不起作用。 我在我的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);
}

Answer 1:

在iOS 6中苹果公司已经通过实施AutoPause API做出核心定位的重大更改。 当应用程序进入后台,并适用于几个标准(即,用户不运动,无位置锁定,用户中止活性)AutoPause API暂停位置更新。 为了准确地处理暂停事件苹果的请求,以帮助更好地预测是否要暂停位置更新设置的活动类型(即导航,健身等)。 该AutoPause API默认情况下,当一个应用程序对iOS 6的编译启用。

最简单的解决方法是通过“pausesLocationUpdatesAutomatically”始终设置为NO禁用AutoPause API现在。 位置更新将在应用云在后台甚至派,喜欢它用在工作<iOS 6中。

更多细节在这里:

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



Answer 2:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation委托犯规存在于iOS 6的了。

而是使用

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

检查的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代表应在所有版本中运行



Answer 3:

你有没有从委托方法的任何消息?

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

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



文章来源: iOS 6 CoreLocation does not work