为什么我的 didUpdate userLocation 方法没有被调用?

Why my didUpdate userLocation method doesn't get called?

我的视图中有一个 MapKit,我想访问 userLocation 数据。然而,实际功能

func firstMapView(_ firstMapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation){
    print("it never gets called")
}

永远不会被调用。

整个代码如下所示:

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{

    @IBOutlet weak var firstMapView: MKMapView!
    let locationManager = CLLocationManager()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        
        firstMapView.delegate = self
    }
    
    
    func firstMapView(_ firstMapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation){
        print("it never gets called")
    }
    
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if status == .authorizedWhenInUse {
            print("Authorized when in use detected")
            locationManager.startUpdatingLocation()
            firstMapView.showsUserLocation = true
        }
    }
}

当我 运行 代码时,我收到调试消息:print("Authorized when in use detected")

我看到了this问题,并试图复制这些东西,但没有帮助。

使用这个委托函数

func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) {
        print(userLocation)

    }

删除这个

func firstMapView(_ firstMapView: MKMapView, didUpdateUserLocation userLocation: MKUserLocation){
        print("it never gets called")
    }