ios - 当 NSAllowsArbitraryLoadsInWebContent 为真时无法使用 AVPlayer 播放视频

标签 ios swift plist avplayer

我有一个带有 AVPlayer 的非常小的应用程序。我正在使用以下代码播放视频:

if let urlToPlay = URL(string: "http://some_video.m3u8") {

    self.player = AVPlayer.init(url: urlToPlay)
    self.player!.play()
}

我还在“Info.plist”文件中添加了一些行,以便能够使用 HTTP 模式播放视频:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

而且效果很好。但后来我发现了一个名为 NSAllowsArbitraryLoadsInWebContent 的标志。我的应用程序中没有任何 WKWebViewUIWebView 实例,因此我认为使用此标志不会导致我的应用程序出现任何崩溃或错误。现在我的文件“Info.plist”有这个片段:

<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

播放器不工作。有人可以向我解释为什么会这样吗?

最佳答案

对于通过 AVFoundation 加载媒体添加 key NSAllowsArbitraryLoadsForMedia 并将其设置为 true。

根据文档:

In iOS 10 and later, and macOS 10.12 and later, the value of this key is ignored—resulting in an effective value for this key of its default value of NO—if any of the following keys are present in your app’s Info.plist file:

NSAllowsArbitraryLoadsForMedia, NSAllowsArbitraryLoadsInWebContent, NSAllowsLocalNetworking

请注意,在生产环境中不鼓励设置任意负载,并且这些标志会触发 AppStore 审查并需要证明这样做的理由。

如需进一步阅读,请访问 ATS Documentation

关于ios - 当 NSAllowsArbitraryLoadsInWebContent 为真时无法使用 AVPlayer 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50506308/

相关文章:

ios - 在我的 plist iOS 上更改值

swift - 将快速字典写入文件

ios - 使用 Swift 的 Firebase

ios - xCode Autolayout 卡在 iPhone 4 模式

ios13 防止下拉滚动到顶部的 tableView 以消除以模态呈现的 viewController 的工作表样式

swift - 在 If/Else 中捕获 Nil 错误

ios - 当使用 nil token 调用 CKFetchRecordChangesOperation 时,将下载哪些记录?

ios - 将一个 View 方向更改为横向

ios - segue后更新类属性中的数组

ios - 用plist替换NS对象数组