带有视频的iOS推送通知未在锁定屏幕上显示

时间:2020-04-04 23:21:42

标签: ios notifications apple-push-notifications push

我正在iphone 7(iOS 13.4)上测试通知服务扩展。我正在发送多种媒体类型(jpg,gif和mp4)。带有jpg和gif的内容显示良好,但是mp4通知仅在iPhone解锁时显示内容。当iphone锁定并且播放通知视频时,虽然听到了视频,但始终不显示白屏,尽管显示了视频。如果我在以白色屏幕播放视频时按触摸按钮,则会显示图像。

在该应用的通知设置中,所有权限都被授予(我认为)。

我是否需要询问用户任何特殊权限?任何想法?

谢谢。

1 个答案:

答案 0 :(得分:0)

是的,您必须在写入completeFileProtectionUntilFirstUserAuthentication期间写授予权限。

下面是示例代码:

`extension UNNotificationAttachment {
  convenience init(gifData: Data, options: [NSObject: AnyObject]?) throws {
    let fileManager = FileManager.default
    let temporaryFolderName = ProcessInfo.processInfo.globallyUniqueString
    let temporaryFolderURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(temporaryFolderName, isDirectory: true)
    try fileManager.createDirectory(at: temporaryFolderURL, withIntermediateDirectories: true, attributes: nil)
    let imageFileIdentifier = UUID().uuidString + ".mp4"
    let fileURL = temporaryFolderURL.appendingPathComponent(imageFileIdentifier)
    try gifData.write(to: fileURL, options: .completeFileProtectionUntilFirstUserAuthentication)
    try self.init(identifier: imageFileIdentifier, url: fileURL, options: options)
  }
}`