检查用户是否允许应用程序使用他们的位置

发布于 2024-08-14 12:25:37 字数 183 浏览 2 评论 0原文

应用程序第一次尝试获取用户位置时,系统会提示他们“想要使用您当前的位置”,然后他们可以点击“不允许”或“确定”。有什么方法可以查明用户是否点击了“确定”或“不允许”?我试图让 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.

Thanks in advance for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-08-21 12:25:37

您第一次获取用户位置的调用将失败,并出现错误,告诉您用户已拒绝位置服务。您的 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";
    }
}

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";
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文