Created
December 5, 2018 12:31
-
-
Save yunustek/adebd8d1506162f5e225c579c453ea00 to your computer and use it in GitHub Desktop.
NotificationService-didReceive-updated
This file contains 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. bestAttemptContent nil olmadığına emin ol | |
let apsData = bestAttemptContent.userInfo["aps"] as? [String: Any], // 2. Payload dan aps'i al | |
let attachmentURLAsString = apsData["mediaUrl"] as? String, // 3. mediaUrl'i al | |
let attachmentURL = URL(string: attachmentURLAsString) else { // 4. String'i URL'e çevir | |
return | |
} | |
// 5. Görüntüyü indir, eğer yok ise bestAttemptContent'i ilet | |
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