Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yunustek/adebd8d1506162f5e225c579c453ea00 to your computer and use it in GitHub Desktop.
Save yunustek/adebd8d1506162f5e225c579c453ea00 to your computer and use it in GitHub Desktop.
NotificationService-didReceive-updated
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