【发布时间】: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