检查用户是否允许该应用使用其位置 [英] check if a user allows the app to use their location

查看:75
本文介绍了检查用户是否允许该应用使用其位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序首次尝试获取用户位置时,系统会提示他们愿意使用您的当前位置",然后他们可以单击不允许"或确定".有什么方法可以找出用户是否点击了确定或不允许?我正在尝试让MKMapView向用户显示当前位置,但是我想根据用户的选择采取不同的操作.

The first time the app tries to get the users location they are prompted with "Would like to use your current location" and they can hit Don't allow or ok. Is there any way to find out if the user has hit ok or don't allow? I'm trying to have the MKMapView show the users current location but I would like to take different actions based on the users selection.

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

Normally you would think there would be a delegate to get this information but there doesn't seem to be.

预先感谢您的帮助.

推荐答案

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

Your first call to get the user's location will fail with an error which tells you the user has denied location services. Your CLLocationManagerDelegate method didFailWithError will be called, as below. (The constants are defined in 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";
    }
}

这篇关于检查用户是否允许该应用使用其位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆