iOS 6 CoreLocation不起作用 [英] iOS 6 CoreLocation does not work

查看:84
本文介绍了iOS 6 CoreLocation不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个位置应用。但核心位置不起作用。
我在iPhone上测试了其他iPhone应用程序。

像google earth,导航软件。
其他应用程序也不起作用。

为什么不更新位置?

为什么'locationManager:didUpdateToLocation:fromLocation:'消息只被叫2次?

I make a location app. But Core Location does not work. I tested other iPhone application on my iPhone.
Like google earth, a navigation software. The other applications do not work also.
Why doesn't update location?
Why 'locationManager:didUpdateToLocation:fromLocation:' message called 2 times only?

也许......我的iPhone坏了?或iOS 6 CoreLocation框架有一些错误?

Maybe... My iPhone broken down? or iOS 6 CoreLocation frameworks have some bug?

位置服务 - 开启iPhone设置

Location service - On on iPhone settings

Info.plist

Info.plist


  • armv7

  • accelerometer

  • location-services

  • gps

  • 麦克风

  • 磁力计

  • armv7
  • accelerometer
  • location-services
  • gps
  • microphone
  • magnetometer

代码示例:

- (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。

In iOS 6 Apple has made breaking changes to Core Location by implementing the AutoPause API. The AutoPause API pauses the location updates when an application goes into the background and applies to a couple of criteria (i.e. user not moving, no location fix, user discontinues activity). To accurately handle pause events Apple requests to help better predicting whether or not to pause location updates setting an activity type (i.e. navigation, fitness, other). The AutoPause API is enabled by default when an application is compiled against iOS 6.

简单的解决方法是通过始终设置'来禁用AutoPause API pausesLocationUpdatesAutomatically'为NO。即使应用程序在后台运行,也会发送位置更新,就像以前在< iOS 6。

The easy fix is to disable the AutoPause API for now by always setting 'pausesLocationUpdatesAutomatically' to NO. Location updates will be send even when the app goes in the background, like it used to work in < iOS 6.

此处有更多详情:

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

这篇关于iOS 6 CoreLocation不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆