首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像未显示在离子ios推送通知中。

图像未显示在离子ios推送通知中。
EN

Stack Overflow用户
提问于 2019-11-20 08:06:06
回答 1查看 867关注 0票数 1

我被困在ios中显示图像,在离子4推送通知。我不知道问题在哪里,我尝试了通知服务扩展和内容extension.but仍然没有显示在notification.It上是完美的工作在安卓系统。

这是notificationService.swift文件:

代码语言:javascript
复制
import UserNotifications
import MobileCoreServices

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

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

        if let bestAttemptContent = bestAttemptContent {

            if let data = bestAttemptContent.userInfo["fcm_options"] as? [String:Any],
             let attachmentString = data["image"] as? String,
                let attachmentUrl = URL(string:attachmentString){
                let session = URLSession(configuration: URLSessionConfiguration.default)
                let downloadTask = session.downloadTask(with:attachmentUrl, completionHandler:{(url, _,error) in
                    if error != nil{
                        print("Error downloading attachment: \(error!.localizedDescription)")
                    }else if let url = url{
                        let attachment = try!UNNotificationAttachment(identifier: attachmentString, url: url, options: [UNNotificationAttachmentOptionsTypeHintKey : kUTTypePNG])
                        bestAttemptContent.attachments = [attachment]
                    }
                    contentHandler(bestAttemptContent)
                })
                downloadTask.resume()
            }
        }
    }

    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }

}

这是notificationViewController.swift文件:

代码语言:javascript
复制
import UIKit
import UserNotifications
import UserNotificationsUI

class NotificationViewController: UIViewController, UNNotificationContentExtension {

    @IBOutlet var label: UILabel?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any required interface initialization here.
    }

    func didReceive(_ notification: UNNotification) {
        print("content",notification);
        self.label?.text = notification.request.content.body
    }
}

这是内容扩展的info.plist。

这是我的通知负载:

{

代码语言:javascript
复制
"google.c.a.ts":"1574236630",
"gcm.notification.sound2":"default",
"google.c.a.e":"1",
"fcm_options":{
      "image":"https:\/\/qph.fs.quoracdn.net\/main-qimg- 
       2409a441a71fdc85cf987c349d364cb4.webp"},
"aps":{
  "alert":{
      "title":"testing",
      "body":"testing...."
   },
  "sound":"default",
  "mutable-content":"1"
  },
"gcm.n.e":"1",
"google.c.a.c_id":"6815041840540114734",
"google.c.a.udt":"0",
"content-available":"1",
"mutable-content":"1",
"gcm.message_id":"1574236630701793"
}

请帮我.,谢谢你提前。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-30 05:35:20

当您使用fcm通知时,然后使用mutable_content:true而不是mutable-content = 1

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

https://stackoverflow.com/questions/58949434

复制
相关文章

相似问题

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