当用户开启时MainViewController
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
}
viewDidLoad()
将运行并出现警报
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Accessing user location to determine the nearest pickup location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Accessing user location to determine the nearest pickup location</string>
主要问题是,如果用户单击不允许,我如何以编程方式检查?例如
// Example code snippet, not from apple officials
if NSlocation is nil then I want to do some alert