作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用程序,可以找到一个人的坐标并将其用于某些代码,当然,如果我没有启用位置,我就无法使用它,但我想检查它是否稍后在网站上启用。示例:
用户登录,转到我的选项卡,没有位置,因此不会显示最近的商店,但是一旦他在那里启用位置,监听器就会告诉我的代码它已打开并相应地执行操作?
我正在考虑使用计时器来检查每一秒......但这似乎有点愚蠢,有其他选择吗?实现什么比较好?
最佳答案
在您需要定位的屏幕中,只需检查定位服务是否启用即可。
override func viewDidLoad()
{
super.viewDidLoad()
self.checkLocationServiceEnabled()
}
func checkLocationServiceEnabled()
{
let locationAuthorizationStatus = CLLocationManager.authorizationStatus()
switch locationAuthorizationStatus {
case .AuthorizedAlways ,.AuthorizedWhenInUse ,.NotDetermined ,.Restricted:
break
case .Denied:
self.alertTurnOnLocationFromDevicePrivacySetting()
}
}
func alertTurnOnLocationFromDevicePrivacySetting()
{
let delayTime = dispatch_time(DISPATCH_TIME_NOW,
Int64(1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
let alertController = UIAlertController(
title: ALERT_TURN_ON_LOCATION_FROM_DEVICE_PRIVACY,
message: "",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: ALERT_OK, style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
self.navigationController?.topViewController!.presentViewController(alertController, animated: true, completion: nil)
}
}
关于swift - 在 swift 3 中,我目前正在使用 Location 为我的应用程序做一些事情,我想检查它是否在该过程稍后的某个时刻启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42154358/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!