首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么HTTP不能使用Firebase iOS推送通知?

为什么HTTP不能使用Firebase iOS推送通知?
EN

Stack Overflow用户
提问于 2020-04-24 10:41:31
回答 1查看 1.4K关注 0票数 1

我在JSON中为iOS推送通知添加了以下选项,并且它使用NotificationServiceExtension成功地显示了带有图像的通知。

代码语言:javascript
复制
"fcm_options": {
  "image": "url-to-image"
}

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

下面是我在里面的实现:

代码语言:javascript
复制
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吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-24 12:31:05

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

我希望这对你的帮助和对我的帮助一样大。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61406492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档