NSAllowsArbitraryLoadsInWebContent为true时,无法使用AVPlayer播放视频 [英] Cannot play videos with AVPlayer when NSAllowsArbitraryLoadsInWebContent is true
问题描述
我有一个使用 AVPlayer
的非常小的应用程序.我正在使用以下代码播放视频:
如果让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
的标志.我的应用程序中没有任何 WKWebView
或 UIWebView
实例,因此我认为使用此标志不会导致应用程序崩溃或错误.现在,我的文件"Info.plist"具有以下片段:
< dict>< key> NSAllowsArbitraryLoads</key>< true/>< key> NSAllowsArbitraryLoadsInWebContent</key>< true/></dict>
播放器无法正常工作.有人可以解释一下为什么会这样吗?
通过AVFoundation加载媒体添加键 NSAllowsArbitraryLoadsForMedia
并将其设置为true.
根据文档:
在iOS 10和更高版本以及macOS 10.12和更高版本中,此密钥的值被忽略-为此键的默认值产生一个有效值值为"NO"(如果您的应用程序中存在以下任何键)Info.plist文件:
NSAllowsArbitraryLoadsForMedia,NSAllowsArbitraryLoadsInWebContent,NSAllowsLocalNetworking
请注意,在生产中不鼓励设置任意负载,并且这些标志会触发AppStore审查,并且需要这样做.
如需进一步阅读,请访问 I also added some lines into the file "Info.plist" to be able to play videos with HTTP schemas: And it works fine. But later I found a flag called And player is not working. Could someone explain me why it happened? For media loading through AVFoundation Add the key According to the documentation: 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 Note that setting arbitrary loads are not encouraged in production and these flags triggers an AppStore review and requires justification for doing so. For further reading visit ATS Documentation 这篇关于NSAllowsArbitraryLoadsInWebContent为true时,无法使用AVPlayer播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
NSAllowsArbitraryLoadsInWebContent
. I don't have any WKWebView
or UIWebView
instances in my application, so I supposed that using of this flag will not lead to any crashes or errors in my application. Now my file "Info.plist" has this fragment:<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
NSAllowsArbitraryLoadsForMedia
and set it to true.