- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用这样的扩展图像在我的应用程序上显示丰富的通知。我已经使用通知服务扩展在应用程序中实现了这一点。
但是当我收到通知时,我只会得到一个缩略图,看起来像这样。当我长按支持 3D 触摸功能的手机时会出现扩展图像,否则它只会在没有 3D 触摸功能的手机上显示缩略图。
我无法在 SO 上找到任何文档或任何问题,这些文档或问题解释了如何在可能的情况下执行此操作。我想知道是否可以在 iOS 上执行此操作,如果不能,是否有任何可能的解决方法来完成此操作?这是我的 NotificationSerivce
延期。任何帮助深表感谢!谢谢!
class NotificationService: UNNotificationServiceExtension {
let fileManager = FileManager()
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 {
// Modify the notification content here...
guard let content = (request.content.mutableCopy() as? UNMutableNotificationContent) else {
return self.contentHandler = contentHandler
}
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
guard let attachmentURL = content.userInfo["attachment-url"] as? String else {
return self.contentHandler = contentHandler
}
guard let fileName = attachmentURL.components(separatedBy: "/").last else {
return self.contentHandler = contentHandler
}
guard let imageData = try? Data(contentsOf: URL(string: attachmentURL)!) else {
return self.contentHandler = contentHandler
}
if let thumbnailAttachment = UNNotificationAttachment.create(imageFileIdentifier: fileName, data: imageData, options: nil) {
bestAttemptContent.attachments = [thumbnailAttachment]
}
contentHandler(bestAttemptContent)
}
}
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)
}
}
}
extension UNNotificationAttachment {
/// Save the image to disk
static func create(imageFileIdentifier: String, data: Data, options: [AnyHashable: Any]?) -> UNNotificationAttachment? {
let fileManager = FileManager.default
let tmpSubFolderName = ProcessInfo.processInfo.globallyUniqueString
let tmpSubFolderURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(tmpSubFolderName, isDirectory: true)
do {
try fileManager.createDirectory(at: tmpSubFolderURL!, withIntermediateDirectories: true, attributes: nil)
let fileURL = tmpSubFolderURL?.appendingPathComponent(imageFileIdentifier)
try data.write(to: fileURL!, options: [])
let imageAttachment = try UNNotificationAttachment(identifier: imageFileIdentifier, url: fileURL!, options: options)
return imageAttachment
} catch let error {
print("error \(error)")
}
return nil
}
}
最佳答案
这是一个非常古老的问题,我想您现在已经发现,您要实现的目标在技术上是不可行的。
通知以折叠形式显示,并且仅当用户 3d 按下(或在没有 3d 触摸的设备的情况下长按)通知时,它们才会以展开形式显示。
关于ios - 通知托盘中带有扩展图像的丰富通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48921706/
我想用个人详细信息来丰富订单集合。 假设我已经(示例在 json 中): [ { "orderId": 123, "quantity": 5, "buyerI
def classify(numb): i=1 j=1 sum=0 for i in range(numb): for j in range(numb)
我正在尝试使用 Spark 处理来自 HBase 表的数据。 This blog post给出了如何使用 NewHadoopAPI 从任何 Hadoop InputFormat 读取数据的示例。 我做
我使用 rich:menuitem 在 Richfaces 上构建了菜单。我需要确定用户单击了哪个菜单项。我尝试使用: 但是,我在请求参数中没有看到参数
注意:我遗漏了不相关的代码 所以我目前正在研究 CCC 1996 P1,这个问题的全部目的是能够计算一个整数输入是完美数、不足数还是充数。我上面列出的代码可以工作,但是我认为它太慢了。该代码会迭代每个
我们正在考虑将 ACS 作为我们的联合 STS。我们可以将自己的自定义 STS 配置为 IP-STS,以及“内置”身份提供商,例如 Facebook、Live 和 Google。然而,我们收到的 cl
我使用以下命令成功创建了一个绘图: # suppose I have a p <- ggplot(data=df, ...) then the following works # I get thos
我正在使用 spring-data-rest 存储库从 REST API 公开常见的 CRUD 操作。 但是我需要为这些操作添加额外的功能。 例如我想向第三方 API 发送关于删除的 HTTP 请求。
我有一个java支持bean,它有一个方法(称之为getDataList()),它返回ArrayList . 在 MyType.java我有很多 setter 和 getter,它们都分配 Strin
我正在使用以下代码:
我正在尝试在facelet组合中使用rich:faces组件rich:jQuery。但我无法产生任何 jquery 调用。 另一个问题...我将如何重写它以落入第一模式
是否可以将 Firebase 上游消息作为可操作通知进行传递?这就是我想要实现的目标:我希望能够将可操作的上游 Firebase 消息从我的 iPad 发送到我的 iPhone。 这可能吗? 这是我的
我有richfaces应用程序。在页面中,定义了 jQuery 函数: 然后我有一些 a4j:commandLink,它应该在完成 ajax 请求时调用该函数。 不幸的是,它不起作用。我知道 on
我有一个 rich:tree 组件,如下使用:
对于客户,我们需要为集成测试生成详细的测试报告,这些报告不仅表明一切都是绿色的,而且还表明测试做了什么。我和我的同事都很懒惰,我们不想破解电子表格或文本文档。 为此,我想了一种方法来记录更复杂的集成测
我在构建 Clojure 时遇到了一些困难基于 Web 应用程序。这是一个简单的 CRUD 应用程序,我开始探索 Clojure 网络生态系统。我正在尝试不同的库,例如 Hiccup , Enlive
我正在编写一个 Flink 流程序,其中我需要使用一些静态数据集(信息库,IB)来丰富用户事件的 DataStream。 对于例如假设我们有一个买家的静态数据集,并且有一个传入的事件点击流,对于每个事
在我的应用程序中,我有一个记录列表。用户可以选择任何记录,更新选项菜单。表格显示了这些记录,它有分页。 所以问题是,当我选择一条记录并对列表进行排序(使我之前选择的记录转到另一个页面)时,我看不到所选
我有一棵树(父级可以有任意数量的子级)和一个用于按名称搜索节点的 inputText 。假设有以下树: A --A1 ----AA1 --A2 其中 A 有两个子级 A1 和 A2,A1 有一个子级
我有一个 rich:dataTable 和一个 rich:dataScroller。当我单击 datascroller 时,我的 dataTable 不会自动刷新以显示正确的页面。但是,如果我按下刷新
我是一名优秀的程序员,十分优秀!