Created
January 31, 2018 12:42
-
-
Save 3257/ebcc6721acb9c7ddf1428f7269ea9b44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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