我是IOS开发的新手。
我正在学习coreLocation,并且需要使用ViewComtroller.swift代码来初始化Location服务,例如


func initLocationManager() {
    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.desiredAccuracy = 5
    locationManager.startUpdatingLocation()
    locationManager.requestAlwaysAuthorization()
    if CLLocationManager.locationServicesEnabled() {
        print("location Services Enabled")
    }
}

  
  我有一个问题,当应用正确启动时,某些命令(例如locationManager.requestAlwaysAuthorization())仅需要运行一次?但是,如果我将其添加到ViewDidLoad()中,它将在我每次返回视图场景时运行。


我需要将它们放入AppDelegate.swift吗?我已经尝试过了。但是我不知道如何将AppDelegate.swift与其他.swift连接

有谁知道一些解决方案来使应用程序更好,更有效地运行

最佳答案

设置此代码行locationManager.delegate = nil后获得位置时,不会调用其委托方法。

08-28 00:20
查看更多