如何请求用户开启定位服务 [英] how to request the user to turn on location services

查看:16
本文介绍了如何请求用户开启定位服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的应用程序来访问用户的当前位置.它在应用程序的开头检查用户是否设置了它.如果不是,我需要该应用程序显示提示以使其使用位置服务.就像警报视图一样,点击按钮后,它会带您进入 iphone 上的定位服务屏幕.

I need my app to access the user's current location. It checks at the beginning of the app if the user has it set or not. and if not i need the app to show a prompt for it to use location services. Like a an alert view and on lick of the button it should take you to the screen of location services on iphone.

推荐答案

您可以通过此代码检查 locationServicesEnabled 以及您的应用程序是否允许定位服务:

You can check the for locationServicesEnabled and if the location service is allowed for your application by this code:

if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {
    //do your works
} else {
   //show an alert
}

这篇关于如何请求用户开启定位服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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