how to request the user to turn on location services(如何请求用户开启定位服务)
问题描述
我需要我的应用程序来访问用户的当前位置.它在应用程序的开头检查用户是否设置了它.如果不是,我需要该应用程序显示提示以使其使用位置服务.就像警报视图一样,点击按钮后,它会带您进入 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
}
这篇关于如何请求用户开启定位服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何请求用户开启定位服务
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
