我只是尝试在我的应用程序的地图上显示用户位置。这是我的单视图控制器的代码
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
fileprivate let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.startUpdatingLocation()
mapView.showsUserLocation = true
}
}
但是当我尝试将 showsUserLocation 设置为 true 时,我收到这样的错误:
2021-03-01 15:40:13.158237+0300 测试[3618:220718] [MKCoreLocationProvider] CLLocationManager(
因此,我尝试了诸如“将位置设置为自定义,而不是在模拟器中设置为无” 或“允许在方案选项中进行位置模拟”之类的解决方案“,没有任何帮助。