簡體   English   中英

創建CLLocationManager時分配CLLocationManager委托

[英]Assigning CLLocationManager delegate when creating the CLLocationManager

我該如何進行以下操作而不會出現錯誤? locationManager.delegate = self表示Cannot assign value of type '(APPLocationManager) -> () -> (APPLocationManager)' to type 'CLLocationManagerDelegate?'

let locationManager: CLLocationManager = {
    let locationManager = CLLocationManager()

    locationManager.delegate = self
    locationManager.activityType = CLActivityType.other
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.pausesLocationUpdatesAutomatically = true
    locationManager.distanceFilter = APPLocationManagerDistanceFilter

    return locationManager
}()

我希望委托是locationManager屬性所屬的類的實例。

在啟動任何服務之前,應將委托對象分配給CLLocationManager對象的委托屬性。 作為-

class ViewController: UIViewController, CLLocationManagerDelegate{
lazy var locationManager: CLLocationManager = {
        let locationManager = CLLocationManager()

        locationManager.delegate = self
        locationManager.activityType = CLActivityType.other
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.pausesLocationUpdatesAutomatically = true
        locationManager.distanceFilter = APPLocationManagerDistanceFilter

        return locationManager
    }()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM