我是一个专业的新手。我想从url下载一个视频,并在ViewController中显示它。当我尝试使用ios设备时,视频将被下载并与fine.But一起使用tvOS,而视频不会被下载。
为什么这么..?
我如何下载和播放的视频在苹果电视。
这是我的密码
设backgroundSessionConfiguration =backgroundSessionConfiguration "backgroundSession")
backgroundSession = Foundation.URLSession(configuration: backgroundSessionConfiguration, delegate: self, delegateQueue: OperationQueue.main)
let url = URL(string: "myURl")!
downloadTask = backgroundSession.downloadTask(with: url)
downloadTask.resume()函数urlSession(_ session: URLSession,downloadTask: URLSessionDownloadTask,didFinishDownloadingTo location: URL){
let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let documentDirectoryPath:String = path[0]
let fileManager = FileManager()
let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath.appendingFormat("/file.mp4"))
if fileManager.fileExists(atPath: destinationURLForFile.path){
showFileWithPath(path: destinationURLForFile.path)
}
else{
do {
try fileManager.moveItem(at: location, to: destinationURLForFile)
// show file
showFileWithPath(path: destinationURLForFile.path)
}catch{
print("An error occurred while moving file to destination url")
}
}
} 发布于 2017-03-29 18:12:07
tvOS中对本地存储有一些限制
您的应用程序只能访问设备本地的500 KB持久存储(使用NSUserDefaults类)。在这个有限的本地存储之外,当空间很小时,所有其他数据都必须由操作系统进行清理。
您可以查看本文档以获得更多详细信息:PG/
https://stackoverflow.com/questions/43062697
复制相似问题