zoukankan      html  css  js  c++  java
  • 转 ios 里如何判断当前应用的定位服务是否可用

    如何在某个程序里面判定当前应用程序的定位服务是否可用,其实没有什么简单的方法。

    这个[CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关,无法检测当前应用是否被关闭,只能通过CLLocationManagerDelegate的locationManager:didFailWithError:方法去检测:

    - (void)locationManager: (CLLocationManager *)manager
    didFailWithError: (NSError *)error {
        
        NSString *errorString;
        [manager stopUpdatingLocation];
        NSLog(@"Error: %@",[error localizedDescription]);
        switch([error code]) {
            case kCLErrorDenied:
                //Access denied by user
                errorString = @"Access to Location Services denied by user";
                //Do something...
                break;
            case kCLErrorLocationUnknown:
                //Probably temporary...
                errorString = @"Location data unavailable";
                //Do something else...
                break;
            default:
                errorString = @"An unknown error has occurred";
                break;
        }
    }
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
    }

    参考:http://blog.csdn.net/jinglijun/article/details/8893062

    另外还有一种变通的方法:不需要通过上述方式来判断用户是否为应用程序开启了定位服务,而是通过判断获取的坐标值是否为空或者为零来判断用户是否为应用程序开启了定位功能。

  • 相关阅读:
    关于图片去水印和转载
    多叉树(森林)转二叉树
    [置顶] 读入优化&输出优化
    【NOI OJ】1816 拨钟问题
    Splay树
    【AVL】宠物收养所
    【树状数组】Stars
    对拍
    使用Mybatis进行多表联查操作
    搜索框自动提示
  • 原文地址:https://www.cnblogs.com/ygm900/p/3103099.html
Copyright © 2011-2022 走看看