为什么我不能使用manager.locationServicesEnabled()

问题描述 投票:-1回答:1

我正在检查是否为该应用启用了位置服务。查看下面的代码,为什么我不能使用“!manager.locationServicesEnabled()”,因为locationManager的类型是CLLocationManager?

override func viewDidLoad() {
    super.viewDidLoad()

    enableLocationServices(manager: locationManager)

}

func enableLocationServices(manager: CLLocationManager) {

    manager.delegate = self

    if !CLLocationManager.locationServicesEnabled() {
        manager.requestWhenInUseAuthorization()
    }
}
ios swift core-location
1个回答
1
投票

假设您在问为什么必须使用CLLocationManager.locationServicesEnabled()而不是manager.locationServicesEnabled(),那么答案就是locationServicesEnabled是一个类型方法,必须在类上调用,而不是类的实例。

在查看方法或属性的文档时,如果它以classstatic开头,那么您可以直接在类,结构或枚举上调用它。如果它不是以classstatic开头,那么你可以在类,结构或枚举的特定实例上调用它。

© www.soinside.com 2019 - 2024. All rights reserved.