我知道这已经回答了,但是最近没有。我正在AppDelegate中设置我的locationManager,如下所示:
import UIKit
import CoreData
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var locationManager:CLLocationManager?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//get user permission to use location data
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestWhenInUseAuthorization()
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.startUpdatingLocation()
return true
}
...
extension AppDelegate {
//MARK: - Location Management
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse {
print("location monitoring allowed!")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error.localizedDescription)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]!) {
let location = locations.last as! CLLocation
//lblLocation.text = String(location.coordinate.latitude) + " " + String(location.coordinate.longitude)
print("*** locationManager Called! ***");
}
}
didChangeAuthorization
被调用,但没有其他代表。我已经在sim卡中尝试过此操作,将其设置为在系留设备上的伦敦位置,并在无系留设备上设置了该应用程序,什么也没有。我确信我缺少简单的东西,任何帮助将不胜感激。
编辑:忘记提及我的plist中始终有隐私设置,用于位置和使用时设置。