Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 当提示输入核心位置时,如何获得用户响应?_Iphone_Objective C_Iphone Sdk 3.0_Core Location - Fatal编程技术网

Iphone 当提示输入核心位置时,如何获得用户响应?

Iphone 当提示输入核心位置时,如何获得用户响应?,iphone,objective-c,iphone-sdk-3.0,core-location,Iphone,Objective C,Iphone Sdk 3.0,Core Location,当我在iPhone上安装我的应用程序时,它会在警报中询问当前位置,并选择“不允许”和“确定”。我如何确定选择了哪个选项?我还想只显示一次此选项。如果用户选择允许查找其当前位置,我希望设备在后台自动获取位置。如果用户拒绝访问位置服务,则调用CLLocationManager委托方法didFailWithError:: - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{

当我在iPhone上安装我的应用程序时,它会在警报中询问当前位置,并选择“不允许”和“确定”。我如何确定选择了哪个选项?我还想只显示一次此选项。如果用户选择允许查找其当前位置,我希望设备在后台自动获取位置。

如果用户拒绝访问位置服务,则调用CLLocationManager委托方法
didFailWithError:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    if (error.code ==  kCLErrorDenied){
            // User denied access to location service       
    }
}

如果用户拒绝访问位置服务,则调用CLLocationManager委托方法
didFailWithError:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    if (error.code ==  kCLErrorDenied){
            // User denied access to location service       
    }
}

控制器应实现
CLLocationManagerDelegate
协议。这定义了您需要实现的两种方法:

  • –locationManager:didUpdateToLocation:fromLocation:

    在这种方法中,您可以使用代码来处理位置更新

  • –位置管理器:错误:

    在这个方法中,您需要编写代码来处理拒绝您的请求或更新失败的用户


  • 一旦用户允许你使用他们的位置,除非他们退出应用程序,否则不会再次提示他们。但是,没有办法阻止手机在用户每次启动应用程序时提示用户。

    您的控制器应该实现
    CLLocationManagerDelegate
    协议。这定义了您需要实现的两种方法:

  • –locationManager:didUpdateToLocation:fromLocation:

    在这种方法中,您可以使用代码来处理位置更新

  • –位置管理器:错误:

    在这个方法中,您需要编写代码来处理拒绝您的请求或更新失败的用户

  • 一旦用户允许你使用他们的位置,除非他们退出应用程序,否则不会再次提示他们。但是,没有办法阻止手机在用户每次启动应用程序时提示用户