AWS Swift中的丰富推送通知

时间:2019-12-04 14:27:14

标签: ios swift amazon-web-services push-notification apple-push-notifications

我正在使用AWS SNS进行推送通知。

当我尝试将Notification Service和Notification内容用于丰富的推送通知时

我正在接收通知,但未点击didReceive函数

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {

        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {

            var urlString:String? = nil
            if let urlImageString = request.content.userInfo["urlImageString"] as? String {
                urlString = urlImageString
            }

            if urlString != nil, let fileUrl = URL(string: urlString!) {
                print("fileUrl: \(fileUrl)")

                guard let imageData = NSData(contentsOf: fileUrl) else {
                    contentHandler(bestAttemptContent)
                    return
                }
                guard let attachment = UNNotificationAttachment.saveImageToDisk(fileIdentifier: "image.jpg", data: imageData, options: nil) else {
                    print("error in UNNotificationAttachment.saveImageToDisk()")
                    contentHandler(bestAttemptContent)
                    return
                }

                bestAttemptContent.attachments = [ attachment ]
            }

            contentHandler(bestAttemptContent)
        }
    }

我在AWS控制台中的原始请求是

{
    "APNSMessage": {
        "aps": {
            "body": "Hello",
            "title": "One Touch",
            "category": "rich-apns",
            "mutable-content": 1,
            "content-available" : true
        }
    }
}

任何人都可以引导我通过...

0 个答案:

没有答案