我创建了UNNotificationServiceExtension
在通知中显示远程附件的子类。随机,附件不显示。
问题难以重现,但一些用户反映,在收到带有图像附件的远程通知后,他们看不到图像。经过一番调试,我曾经遇到过这个问题。我注意到downloadTask()
有空location
但response
状态码是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
了已获取附件的 url。我不知道这个问题的原因是什么。
我在真机 iPhone 6S Plus、iOS 10.3.3 上进行了测试。
有没有人有类似的问题?有什么建议我会做错什么吗?