我有一个播放视频的应用程序。这是与iOS 11,12和iOS 13.在iOS上11和12兼容,视频播放可以正常运行的使用无论是预期的AVPlayerViewController,甚至只是AVPlayerLayer。
但是,在 iOS 13 上,我开始收到报告,称很多用户在更新 iOS 时突然无法加载视频(或仅加载音频或仅加载第一帧)。我很难复制它,但有些人提到它主要发生在网络连接不良的情况下,并且使用 Network Link Conditioner 果然我能够复制它。
它特别影响 HLS 视频(例如,Reddit 使用的花哨的直播兼容视频)。它继续与 MP4 一起正常工作。这是一个失败的示例 URL:https : //v.redd.it/gl3chx2kd4v31/HLSPlaylist.m3u8
这是触发它的网络链接调节器配置文件:https : //i.imgur.com/XWsKUeM.jpg
这是触发它的示例项目,同时显示 AVPlayerViewController 和 AVPlayer(点击下载,Google 很奇怪):https : //drive.google.com/file/d/1RS5DvUypdOLFCYJe1Pt2Ig0fQljZDLs2/view
这是使用 AVPlayerViewController 展示它的示例代码:
let assetURL = URL(string: "https://v.redd.it/gl3chx2kd4v31/HLSPlaylist.m3u8")!
// The following MP4 URL *does* work, for instance
// let assetURL = URL(string: "https://giant.gfycat.com/DependentFreshKissingbug.mp4")!
let player = AVPlayer(url: assetURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
} …Run Code Online (Sandbox Code Playgroud) Apologies for the title, a little tricky to explain.
Imagine a user is listening to Spotify or something in the background while using my app, and they tap on a video to play it. The video defaults to muted, so Spotify continues. THEN the user hits unmute, so Spotify will pause, and the now unmuted video audio will start playing.
Now, turns out the video's audio wasn't so interesting and the user would prefer to listen to their music, so …
iOS 具有以下调用方法,因此您可以通过通知中心或设置应用程序向用户提供自定义通知设置:
func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
// Open up a Settings view controller within your app or something
}
Run Code Online (Sandbox Code Playgroud)
在其中,您将打开一些应用内设置视图控制器。
在 iOS 12 上这很容易,找到活动窗口,找到 rootViewController 并将设置屏幕扔到它上面。
在 iOS 13 上你(可以)有多个窗口,所以我假设这个方法可以在其中任何一个上调用?
假设您有 5 个应用程序窗口在后台打开,然后您打开“设置”应用程序并请求应用程序的通知设置。它使用哪个窗口?我如何知道要将设置屏幕添加到哪个窗口/视图控制器?我不想随机选择一个并且不小心将它添加到背景中的一个而不是打开的那个。
UNNotificationResponse另一方面,确实有一种targetScene方法,因此如果您的应用程序是从通知中打开的,您就可以知道要使用哪个窗口,但这种方法似乎缺乏它。
我应该遍历应用程序可用的所有窗口场景并在前台找到一个吗?
如果我编译到 iOS 12 设备(不使用 UIScene)和 AirPlay Mirror 到我的 Apple TV,应用程序会按预期镜像到电视。
在 iOS 13 设备上,它似乎将其视为外部显示器,在其中格式化以适合屏幕(但我无法控制它)。
我更喜欢只是镜像它的旧功能。
如何在 iOS 13 上完成镜像?我在文档中挖掘:
application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
Run Code Online (Sandbox Code Playgroud)
并且在UISceneConfiguration那里有一个role属性(UISceneSession.Role.windowExternalDisplay当我尝试 AirPlay Mirror 时它有)但它似乎没有任何价值,如UISceneSession.Role.windowMirror.