【问题标题】:iOS Push notification with video is not showing on lock screen带有视频的 iOS 推送通知未在锁定屏幕上显示
【发布时间】:2020-07-17 01:12:04
【问题描述】:
我正在 iphone 7 (iOS 13.4) 上测试通知服务扩展。我正在发送多种媒体类型(jpg、gif 和 mp4)。 jpg 和 gif 的内容显示良好,但 mp4 通知仅在 iphone 解锁时显示内容。当 iphone 被锁定并且播放通知视频时,虽然可以听到视频,但没有显示图像,一直是白屏。如果我在白屏播放视频时按下触摸按钮,则会出现图像。
在应用的通知设置中,所有权限都被授予(我认为)。
我是否必须要求用户提供任何特殊权限?任何想法?
谢谢。
【问题讨论】:
标签:
ios
notifications
apple-push-notifications
push
【解决方案1】:
是的,您必须在写入 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)
}
}`