我试图在ios 10中实现丰富的远程通知。我实现了这个代码。收到通知后的控件会在这里,但我不知道如何下载图像并显示在通知中。提前致谢。对于丰富的远程通知使用UNNotificationServiceExtension
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
//print("title for image = \(bestAttemptContent.title)")
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
感谢您的回复@Rajat。我试过这个,但它仍然没有下载图像。仍然只显示文本数据。我不知道我在做什么错 – Prajyot
检查文件是否正在下载,也检查你是否从通知数据中获得有效的URL – Rajat
是的,网址是有效的。但是他们要在什么地方储存?我看过照片,没有。 – Prajyot