Служба определения местоположения в расширении службы уведомлений
Я пытаюсь использовать инфраструктуру CoreLocation внутри моей службы уведомлений, но похоже, что метод LocationManager Delegate никогда не вызывается. Что случилось?
Мой код:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if bestAttemptContent != nil {
if CLLocationManager.locationServicesEnabled() {
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
} else {
//use this for debug
self.bestAttemptContent?.title = "Location service disabled"
self.contentHandler!((self.bestAttemptContent!))
}
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationManager.stopUpdatingLocation()
//use this for debug
self.bestAttemptContent?.title = "Location was updated"
self.contentHandler!((self.bestAttemptContent!))
}