【问题标题】:Cannot attach media in remote notification using notification service extension in ios 10无法使用 ios 10 中的通知服务扩展在远程通知中附加媒体
【发布时间】:2017-02-01 12:35:17
【问题描述】:

我可以使用
修改远程通知的内容 "func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)" 的通知服务扩展。但无法下载图像或电影并将它们作为附件添加到内容中。

我们如何使用这种方法在远程通知中附加媒体。

【问题讨论】:

    标签: ios swift unnotificationrequest


    【解决方案1】:

    我写了一个扩展来简化这个过程,见这里: UNNotificationAttachment with UIImage or Remote URL

    然后你可以像这样包含图像

    let identifier = ProcessInfo.processInfo.globallyUniqueString
    let content = UNMutableNotificationContent()
    content.title = "Hello"
    content.body = "World"
    if let attachment = UNNotificationAttachment.create(identifier: identifier, image: myImage, options: nil) {
        // where myImage is any UIImage that follows the 
        content.attachments = [attachment] 
    }
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120.0, repeats: false)
    let request = UNNotificationRequest.init(identifier: identifier, content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request) { (error) in
        // handle error
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2017-02-01
      • 2017-01-16
      • 2017-02-23
      • 1970-01-01
      相关资源
      最近更新 更多