【发布时间】:2016-07-19 18:01:08
【问题描述】:
在我的应用程序中,我尝试从 GPS 获取经度和纬度。为此,我必须询问用户是否有权访问他的位置。在我这样做之前,我添加到 Info.plist 这两个规则:Privacy - Location When In Use Usage Description 和 Privacy - Location Always Usage Description,然后在 AppDelegate 我询问是否允许这样做(SWIFT 3.0):
if CLLocationManager.locationServicesEnabled() == true {
let localisationManager = CLLocationManager()
localisationManager.requestWhenInUseAuthorization()
localisationManager.startUpdatingLocation()
}
在运行应用程序时我可以看到UIAlertController 一会儿,但几乎在同一时间它消失了,我没有时间点击Allow 并且我无法使用 GPS。如何解决?
我的问题的有效解决方案:
我在class LocationManager and then I used it in function. 中创建了单独的变量var locationManager = CLLocationManager()
【问题讨论】:
标签: ios swift core-location uialertcontroller ios10