Dear Team,
We are trying to integrate Rich Push Notification in ionic capacitor project. As per instructions, we created/added notification service extension. But it is not calling notification service and not displaying images in push notification.
Below is the source code written to download image from the url (shared via payload)
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
if let attachmentString = bestAttemptContent.userInfo["media_attachment"] as? String,
let attachmentUrl = URL(string: attachmentString) {
let session = URLSession(configuration: URLSessionConfiguration.default)
let downloadTask = session.downloadTask(with: attachmentUrl, completionHandler: { (url, _, error) in
if let error = error {
print("Error downloading attachment: \(error.localizedDescription)")
} else if let url = url {
let attachment = try! UNNotificationAttachment(identifier: attachmentString,
url: url,
options: [UNNotificationAttachmentOptionsTypeHintKey: kUTTypePNG])
bestAttemptContent.attachments = [attachment]
}
contentHandler(bestAttemptContent)
})
downloadTask.resume()
}
}
}
Payload:
{
"alert": {
"title": "Test",
"subtitle": "Test test",
"body": "This episode we talk about Clean Architecture with Antonio Leiva."
},
"mutable-content": 1
},
"media_attachment": "https://koenig-media.raywenderlich.com/uploads/2016/11/Logo-250x250.png"
}
POD File:
target "NotificationService" do
pod 'AirshipExtensions/NotificationService'
end
Comments
1 comment