【问题标题】:Why are HTTP image URLs not working with Firebase iOS push notifications?为什么 HTTP 图像 URL 不适用于 Firebase iOS 推送通知?
【发布时间】:2020-04-24 10:41:31
【问题描述】:

我在 iOS 推送通知的 JSON 播放负载中添加了以下选项,它使用 Notification Service Extension 成功显示带有图像的通知。

"fcm_options": {
  "image": "url-to-image"
}

但是,当图像 URL 是 HTTP 而不是 HTTPs 时,它不会在通知栏中填充图像。该图片在App内内容详情页UIImageView加载成功。

这是我的内部实现:

override func didReceive(_ request: UNNotificationRequest, 
                             withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)
{
    self.contentHandler = contentHandler
    bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

    if let bestAttemptContent = bestAttemptContent {

        // 1. Modify the notification content here...
        bestAttemptContent.title = "\(bestAttemptContent.title)"
        bestAttemptContent.body = "\(bestAttemptContent.body)"

        // 2. Modify badge count
        if let userDefaults = UserDefaults(suiteName: "group.myBundleId") {

            let badgeCount = userDefaults.integer(forKey: "badgeCount")

            if badgeCount > 0 {
                userDefaults.set(badgeCount + 1, forKey: "badgeCount")
                bestAttemptContent.badge = badgeCount + 1 as NSNumber
            } else {
                userDefaults.set(1, forKey: "badgeCount")
                bestAttemptContent.badge = 1
            }
        }

        // 3. Load image

        /* NOTE: Instead of completing the callback with 
                 self.contentHandler(self.bestAttemptContent);,
                 complete it with FIRMessaging extensionHelper */

        //contentHandler(bestAttemptContent)

        Messaging.serviceExtension().populateNotificationContent(bestAttemptContent, 
                                                                 withContentHandler: contentHandler)
    }
}

我该怎么办?是否需要提供带有HTTPs 的图片URL?

【问题讨论】:

    标签: ios https push-notification firebase-cloud-messaging apple-push-notifications


    【解决方案1】:

    很久以前我做了一个带有丰富推送通知的应用程序,这是我用来做的教程 https://medium.com/@lucasgoesvalle/custom-push-notification-with-image-and-interactions-on-ios-swift-4-ffdbde1f457

    我希望它对你和我一样有帮助。

    【讨论】:

    • 添加 App Transport Security Settings 并将 Allow Arbitrary Loads 设置为 YES 似乎有效..
    猜你喜欢
    • 2020-05-22
    • 2018-05-25
    • 2021-03-31
    • 2017-01-22
    • 2021-11-21
    • 2017-04-09
    • 2016-11-29
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多