I created subclass of UNNotificationServiceExtension
to show remote attachment in notification. Randomly, attachment doesn't show.
Issue is hard to reproduce, but some users reported, that after receive remote notification with image attachment, they can't see image. After some debugging, I encountered this issue once. I noticed that downloadTask()
had empty location
but response
's status code was 200
.
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// ...
// Dowload remote media file
URLSession.shared.downloadTask(with: attachmentUrl) { (location: URL?, response: URLResponse?, error: Error?) in
// ...
self.contentHandler!(self.bestAttemptContent!)
}.resume()
}
Moreover, error
variable contained:
"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\"
UserInfo={NSErrorFailingURLKey=https://<url_to_media_attachment>, NSErrorFailingURLStringKey=https://<url_to_media_attachment>}"
Seems attachment is fetched correctly but URLSession
loses location
url for fetched attachment. I have no idea what is the reason of that issue.
I tested on real device iPhone 6S Plus, iOS 10.3.3.
Did anyone have similar problem? Any suggestion what could I do incorrectly?