OGeek|极客世界-中国程序员成长平台

标题: ios - 当 NSAllowsArbitraryLoadsInWebContent 为真时,无法使用 AVPlayer 播放视频 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:11
标题: ios - 当 NSAllowsArbitraryLoadsInWebContent 为真时,无法使用 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>

播放器不工作。有人能解释一下为什么会这样吗?



Best Answer-推荐答案


对于通过 AVFoundation 加载媒体,添加键 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4