UNNotificationServiceExtension sometimes doesn't show image

╄→гoц情女王★ 提交于 2019-12-08 06:07:14

问题


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?

来源:https://stackoverflow.com/questions/45418450/unnotificationserviceextension-sometimes-doesnt-show-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!