ios 10에서 풍부한 원격 알림을 구현하려고합니다.이 코드를 구현했습니다. 알림을받은 후 컨트롤이 여기에 있지만 이미지를 다운로드하고 알림을 표시하는 방법을 모르겠습니다. 미리 감사드립니다.풍부한 원격 알림을 위해 UNNotificationServiceExtension 사용
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
//print("title for image = \(bestAttemptContent.title)")
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
@Rajat 답장을 보내 주셔서 감사합니다. 이것을 시도했지만 여전히 이미지를 다운로드하지 않습니다. 텍스트 데이터 만 계속 표시합니다. 내가 잘못하고있는 것이 무엇인지 모르겠다. – Prajyot
파일 다운로드 여부를 확인하고 알림 데이터에서 올바른 URL을 확인하십시오. – Rajat
예 url이 유효합니다. 그러나 어떤 위치에 그들은 저장 될 예정입니까 ?? 나는 사진을 통해 갔다. – Prajyot