boo*_*ung 3 iphone core-location ios ios6
我做了一个位置应用程序.但核心位置不起作用.我在iPhone上测试了其他iPhone应用程序.
像谷歌地球,导航软件.其他应用程序也不起作用.
为什么不更新位置?
为什么'locationManager:didUpdateToLocation:fromLocation:'消息只被调用2次?
也许......我的iPhone崩溃了?或iOS 6 CoreLocation框架有一些错误?
位置服务 - 开启iPhone设置
的Info.plist
代码示例:
- (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);
}
Run Code Online (Sandbox Code Playgroud)
在iOS 6中,Apple通过实施AutoPause API对Core Location进行了重大更改.当应用程序进入后台时,AutoPause API会暂停位置更新,并应用于几个条件(即用户不移动,没有位置修复,用户中断活动).为了准确处理暂停事件Apple请求帮助更好地预测是否暂停位置更新设置活动类型(即导航,健身,其他).在针对iOS 6编译应用程序时,默认情况下会启用AutoPause API.
简单的解决方法是暂时禁用AutoPause API,始终将'pausesLocationUpdatesAutomatically'设置为NO.即使应用程序在后台运行,也会发送位置更新,就像以前在<iOS 6中工作一样.
更多细节在这里:
| 归档时间: |
|
| 查看次数: |
5443 次 |
| 最近记录: |