Skip to content

Instantly share code, notes, and snippets.

@3257
Created January 31, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3257/ebcc6721acb9c7ddf1428f7269ea9b44 to your computer and use it in GitHub Desktop.
Save 3257/ebcc6721acb9c7ddf1428f7269ea9b44 to your computer and use it in GitHub Desktop.
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
guard let bestAttemptContent = bestAttemptContent, // 1. Make sure bestAttemptContent is not nil
let apsData = bestAttemptContent.userInfo["aps"] as? [String: Any], // 2. Dig in the payload to get the
let attachmentURLAsString = apsData["attachment-url"] as? String, // 3. The attachment-url
let attachmentURL = URL(string: attachmentURLAsString) else { // 4. And parse it to URL
return
}
// 5. Download the image and pass it to attachments if not nil
downloadImageFrom(url: attachmentURL) { (attachment) in
if attachment != nil {
bestAttemptContent.attachments = [attachment!]
contentHandler(bestAttemptContent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment