UNNotificationServiceExtension有时不显示图像

时间:2017-07-31 14:20:41

标签: ios swift ios-app-extension nsurlsessiondownloadtask remote-notifications

我创建了UNNotificationServiceExtension的子类,以在通知中显示远程附件。随机地,附件没有显示。

问题难以重现,但有些用户报告说,在收到带图片附件的远程通知后,他们无法看到图片。经过一些调试,我遇到过这个问题一次。我注意到downloadTask()为空locationresponse的状态代码为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()
}

此外,error变量包含:

"Error Domain=NSPOSIXErrorDomain Code=2 \"No such file or directory\" 
UserInfo={NSErrorFailingURLKey=https://<url_to_media_attachment>, NSErrorFailingURLStringKey=https://<url_to_media_attachment>}"

似乎正确获取了附件,但URLSession丢失了location个网址,用于获取附件。我不知道这个问题的原因是什么。

我在真实设备iPhone 6S Plus,iOS 10.3.3上测试过。

有没有人有类似的问题?有什么建议我可以做错吗?

0 个答案:

没有答案
相关问题