1

I can modify the content of remote notification using
"func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)" of notification service extension. But could'nt download images or movies and add them as attachments to the content.

How can we attach medias in remote notification using this method.

Ammaiappan
  • 539
  • 3
  • 22
Mitha
  • 21
  • 3

1 Answers1

0

I wrote an extension to simplify the process, see here: UNNotificationAttachment with UIImage or Remote URL

Then you can include the image like this

let identifier = ProcessInfo.processInfo.globallyUniqueString
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "World"
if let attachment = UNNotificationAttachment.create(identifier: identifier, image: myImage, options: nil) {
    // where myImage is any UIImage that follows the 
    content.attachments = [attachment] 
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120.0, repeats: false)
let request = UNNotificationRequest.init(identifier: identifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
    // handle error
}
Community
  • 1
  • 1
MarkHim
  • 5,686
  • 5
  • 32
  • 64