【问题标题】:Core Location not working in simulator Xcode 9.4.1核心位置在模拟器 Xcode 9.4.1 中不起作用
【发布时间】:2018-08-29 22:57:30
【问题描述】:

我有以下代码:

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】:

问题是func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) 已经过时多年了。更新现代 Swift 的代码。以下是声明的外观:

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

【讨论】:

    猜你喜欢
    • 2011-11-30
    • 2014-11-19
    • 2011-12-07
    • 2020-03-10
    • 2019-02-20
    • 1970-01-01
    • 2011-04-01
    • 2014-11-29
    • 2014-09-12
    相关资源
    最近更新 更多