Delegasi CLLocationManager tidak pernah dipanggil. Ini kode saya:
import UIKit
import CoreLocation
class LocationController: UITableViewController, CLLocationManagerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled())
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
// ask permission - NOT NECESSARY IF YOU ALREADY ADDED NSLocationAlwaysUsageDescription IT UP INFO.PLIST
locationManager.requestAlwaysAuthorization()
// when in use foreground
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
else{
print("set up location access in info.plist")
}
}
private func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("locationmanager got called")
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
}
pengaturan info.plist:
Pengaturan Simulator saya: