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
}
这篇关于如何请求用户开启定位服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何请求用户开启定位服务


- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01