核心位置不适用于模拟器Xcode 9.4.1

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

我有以下代码:

import CoreLocation

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

然后:

 locationManager.delegate = self
 locationManager.desiredAccuracy = kCLLocationAccuracyBest
 locationManager.requestWhenInUseAuthorization()
 locationManager.startUpdatingLocation()

然后我在VC中实现较低的委托方法

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

        for currentLocation in locations{
            print("\(index)\(currentLocation)")
        }
        print("Did Location Delegate get called?")
        let location: CLLocation = locations.first as! CLLocation
        print(location)
        self.lat = String(format: "%f", location.coordinate.latitude)
        self.long = String(format: "%f", location.coordinate.longitude)
        }

在构建阶段,“Link Binary With Libraries”已选择CoreLocation.framework。

plist中存在适当的隐私:隐私 - 位置使用说明以及隐私 - 使用时的位置用法说明。

位置仍然没有得到。我在针对iOS 11的Xcode 9.4.1中使用模拟器。我在这里缺少什么?

ios core-location
1个回答
0
投票

问题是func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)已经过时了。更新现代Swift的代码。这是宣言的外观:

https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423615-locationmanager

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