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 ,留空即可。
这样就可以开启 “始终” 定位开关。
原因在于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 ,留空即可。
这样就可以开启 “始终” 定位开关。
相关文章推荐
- iOS8 兼容 请求开启远程推送代码
- iOS8 兼容 请求开启远程推送代码
- ios8 sdk 推送兼容代码 registerForRemoteNotifications
- 一段关于浏览器兼容的事件定位代码,经过测试!
- IE浏览器兼容模式自动开启代码
- iOS8定位问题,在iPhone设置中点击开启定位功能直接崩溃的问题
- ios8之后开启定位服务问题
- IOS8 IOS9 高德地图弹出是否允许定位框功能代码
- ios8以后要自己开启定位权限
- iOS8无法开启定位问题
- IOS 判断定位服务是否开启代码
- 添加到收藏夹代码(兼容几乎所有的浏览器)
- Delphi开启Windows目录对话框代码
- MS-VC 使用MAP文件快速定位程序崩溃代码行
- 可以自己实现重定位的代码
- 网页定位代码 随心所欲定位
- 发一段开启摄像头的代码
- firefox 和 ie 事件处理的细节,研究,再研究-----书写同时兼容ie和ff的事件处理代码
- 比较常见的拖动层代码。(兼容FF)
- 兼容FF&IE的滚动代码