简体   繁体   English

获取位置权限对话框的结果

[英]Getting results of location permission dialog

I am doing this tutorial that would return the GPS coordinates. 我正在做本教程 ,将返回GPS坐标。 When I run the application on the iPhone, I am first presented with the UIAlertView asking permission to access my GPS coordinates. 当我在iPhone上运行该应用程序时,首先会看到UIAlertView要求获得访问我的GPS坐标的权限。

I need to know from where this UIAlertView is thrown? 我需要知道从哪里抛出该UIAlertView Is it from the OS? 是来自操作系统吗? Can we capture this method? 我们可以捕获这种方法吗? When the user clicks on "Allow" or "Don't allow", can I print his choice to the console? 当用户单击“允许”或“不允许”时,我可以将其选择打印到控制台吗?

How can I do this programatically? 如何以编程方式执行此操作? Is there an event for this? 有活动吗?

This alert is shown by the OS. 该警报由操作系统显示。 The usage of location-based API must be permitted by the user. 用户必须允许使用基于位置的API。 You can ask the CLLocationManager for the current authorizationStatus and be notified when the status changes (delegate method will be called). 您可以向CLLocationManager询问当前的authorizationStatus并在状态更改时收到通知(将调用delegate方法)。 Note that the user also can disable location services later in the settings app. 请注意,用户稍后也可以在设置应用中禁用位置服务。

I assume you are using CLLocationManager. 我假设您正在使用CLLocationManager。 Your delegate will get locationManager:didChangeAuthorizationStatus when the applications ability to use the API changes. 当应用程序使用API​​的能力发生更改时,您的委托将获得locationManager:didChangeAuthorizationStatus。

Edit: The first time your application attempts to use the service, the user will be prompted. 编辑:您的应用程序第一次尝试使用该服务时,将提示用户。 If the user answers No, your application will not be able to use the service unless they go to Settings->General->Location Services and change the setting for your application. 如果用户回答“否”,则您的应用程序将无法使用该服务,除非他们转到“设置”->“常规”->“位置服务”并更改应用程序的设置。

If you query the API for status and are disallowed, you could put up your own pop-up and instruct the user on how to change the setting for your application. 如果查询API的状态但不被允许,则可以放置自己的弹出窗口并指导用户如何更改应用程序的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM