Trying to work with location tracking for the watchkit app. But the code flow doesn't go in the didupdatelocation method. What is wrong?
import WatchKit
import Foundation
import CoreLocation
class HomeInterfaceController: WKInterfaceController,CLLocationManagerDelegate {
var locationManager:CLLocationManager!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure location manager
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.distanceFilter = 20.0
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
// Request location authorization
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status.rawValue {
case 0:
print("Not determined")
case 1:
print("Restricted Access")
case 2:
print("Denied")
case 3:
print("Authorized Always")
locationManager.requestLocation()
break
case 4:
print("Authorization When in use")
locationManager.requestLocation()
default:
break
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let currentLocation = locations.last! as CLLocation
print(locations.last?.coordinate)
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}