[英]iOS Push notification with video is not showing on lock screen
我正在 iphone 7 (iOS 13.4) 上测试通知服务扩展。 我正在发送多种媒体类型(jpg、gif 和 mp4)。 jpg 和 gif 的内容显示良好,但 mp4 通知仅在 iphone 解锁时显示内容。 当 iphone 被锁定并且播放通知视频时,虽然可以听到视频,但没有显示图像,一直是白屏。 如果我在以白屏播放视频时按下触摸按钮,则会出现图像。
在应用程序的通知设置中,所有权限都被授予(我认为)。
我是否必须向用户询问任何特殊权限? 任何想法?
谢谢。
是的,您必须在写入 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)
}
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.