我在JSON中为iOS推送通知添加了以下选项,并且它使用NotificationServiceExtension成功地显示了带有图像的通知。
"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吗?
发布于 2020-04-24 12:31:05
很久以前,我制作了一个带有富推送通知的应用程序,这是我在那个https://medium.com/@lucasgoesvalle/custom-push-notification-with-image-and-interactions-on-ios-swift-4-ffdbde1f457中使用的教程
我希望这对你的帮助和对我的帮助一样大。
https://stackoverflow.com/questions/61406492
复制相似问题