Hello everyone!
Has anyone managed to get it working?
I have two entries in Widget's info.plist as @markdaws mentioned.
My location manager wrapper looks this way:
Code Block swift| class WidgetLocationManager: NSObject, CLLocationManagerDelegate { |
| var locationManager: CLLocationManager? { |
| didSet { |
| self.locationManager!.delegate = self |
| } |
| } |
| private var handler: ((CLLocation) -> Void)? |
| func fetchLocation(handler: @escaping (CLLocation) -> Void) { |
| self.handler = handler |
| self.locationManager!.requestLocation() |
| } |
| func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
|
| self.handler!(locations.last!) |
|
| } |
| func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { |
| print(error) |
| } |
| } |
And getTimeline function this way:
Code Block swift| var widgetLocationManager = WidgetLocationManager() |
| func getTimeline(for configuration: SelectPlaceIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { |
| if widgetLocationManager.locationManager == nil { |
| widgetLocationManager.locationManager = CLLocationManager() |
| widgetLocationManager.locationManager!.requestWhenInUseAuthorization() |
| } |
| widgetLocationManager.fetchLocation(handler: { location in |
| print(location) |
| ........ |
| }) |
| } |
When locationManager.requestLocation() is being called, authorisation status is authorisedWhenInUse, but delegate's method is never being called. What am I missing?