您的位置:首页 > 移动开发 > IOS开发

iOS8 开启定位兼容代码

2014-11-21 17:33 218 查看
      升级了ios8后发现,程序在ios8系统的设置里面不能打开定位开关了,一旦打开,就会被关闭。

     原因在于ios8需要做特殊处理。

     

     需要做如下的处理:

     //开启后台定位
-(void)startSignificantChangeUpdates
{
NSLog(@"=======startSignificantChangeUpdates=========");

// if location services are restricted do nothing
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
{
//弹出 请打开定位的提示
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"text_location_service_off_warning_title", @"") message:NSLocalizedString(@"text_location_service_off_warning_content", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"text_no", @"") otherButtonTitles:NSLocalizedString(@"text_ok", @""), nil];

[alert show];

return ;
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
[locationManager requestAlwaysAuthorization];
}
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];

isUpdatingLocation = YES;
}

然后还需要在plist文件中,添加两个字段:

NSLocationAlwaysUsageDescription  跟 NSLocationWhenInUseDescription 

类型为string  ,留空即可。

这样就可以开启 “始终” 定位开关。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: