显示约3秒并解雇
但是当我在正常课程中创建它显示所有时间然后用户点击以回答允许/不允许
public class Location: NSObject, CLLocationManagerDelegate{
public var locationManager = CLLocationManager()
public func RequestLocation(){
self.locationManager.delegate = self
if CLLocationManager.authorizationStatus() == .notDetermined {
self.locationManager.requestWhenInUseAuthorization()
}
locationManager.startUpdatingLocation()
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
}
编辑 - 添加了OP代码以显示Location
实例化
import UIKit
import DemoLocation
class ViewController: UIViewController {
deinit {
print("deinit")
}
let location = Location()
override func viewDidLoad() {
super.viewDidLoad()
location.RequestLocation()
}
}
答案 0 :(得分:0)
这是因为只要释放CLLocationManager
,对话框就会立即消失。
您应该通过实例或静态变量
保存对locationManager
的引用
要解决此问题,您必须更改类中存在的CLLocationManager
与要与该类一起发布的当前实例。
有关CLLocationManager
的更多帮助,请参阅Apple API Reference