【发布时间】:2012-09-25 04:16:43
【问题描述】:
我制作了一个位置应用程序。但核心位置不起作用。
我在我的 iPhone 上测试了其他 iPhone 应用程序。
像google earth,一个导航软件。
其他应用程序也不起作用。
为什么不更新位置?
为什么 '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);
}
【问题讨论】:
-
您是否清除了安全设置?
-
是的,我设置了定位服务 - 开启。谢谢。
-
设置 -> 常规 -> 重置 -> 重置位置和隐私。
-
感谢 jessedc。我确实重置了位置和隐私。但我的 iPhone 不工作 TT。
-
问题不在 iOS 6 中。CLLocationManager 适用于许多应用程序。
标签: iphone ios ios6 core-location