我能够使用以下代码访问设备的位置。我使用的是MAPKIT而不是共定位。我认为此实例CLLocationManager()
和方法requestAlwaysAuthorization()
仅通过Corelocation框架可用?
import UIKit
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
locationManager.delegate = self
self.locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
for currentlocation in locations{
print("(index): (currentlocation)")
}
}
}
mapkit导入coreLocation,因此您不需要。就像您不需要进口基础,因为您从Uikit那里得到了基础。