【问题标题】:check if a user allows the app to use their location检查用户是否允许应用使用他们的位置
【发布时间】:2010-12-26 16:27:52
【问题描述】:

当应用第一次尝试获取用户位置时,系统会提示他们“想使用您当前的位置”,他们可以点击不允许或确定。有什么方法可以确定用户是否点击了确定或不允许?我正在尝试让 MKMapView 向用户显示当前位置,但我想根据用户的选择采取不同的操作。

通常您会认为会有一个代表来获取此信息,但似乎没有。

提前感谢您的帮助。

【问题讨论】:

    标签: iphone location mkmapview cllocationmanager


    【解决方案1】:

    您第一次获取用户位置的调用将失败,并显示一个错误,告诉您用户已拒绝位置服务。您的CLLocationManagerDelegate 方法didFailWithError 将被调用,如下所示。 (常量定义在CLError.h

    - (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
    {
        switch([anError code])
        {
        case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
        break;
    
        case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
        message = @"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
        break;
    
        case kCLErrorNetwork: // general, network-related error
        message = @"Flook can't find you - please check your network connection or that you are not in airplane mode";
        }
    }
    

    【讨论】:

    • startMonitoringSignificantLocationChanges 似乎不是这种情况
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多