iOS项目开发小技巧 (五) --检测是否打开应用定位及跳到系统设置定位页

来源:互联网 发布:太空电梯 知乎 编辑:程序博客网 时间:2024/06/08 04:11

iOS项目开发小技巧 (四) –实现类似弹出窗口(View)

app 中用到定位的,需要判断如下方法:

-(BOOL)isLocationServer{//第一个判断是获取系统定位开启状态   第二个是获取应用定位开启状态    if ([CLLocationManager locationServicesEnabled] &&        ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways         || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {            //定位功能可用,开始定位            return YES;                   }    else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){        NSLog(@"定位功能不可用,提示用户或忽略");        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"赶快设置定位功能,让RyFit更好的服务您" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去设置", nil];        [alertView show         ];        return NO;    }    return NO;}#pragma mark - alertView delegate-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if (buttonIndex == 1) {        NSLog(@"去设置");        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];        if ([[UIApplication sharedApplication] canOpenURL:url]) {            //如果点击打开的话,需要记录当前的状态,从设置回到应用的时候会用到            [[UIApplication sharedApplication] openURL:url];        }    }}
0 0