简体   繁体   English

ios:我应该在哪里保存应用程序数据文件,Temp或Document文件夹?

[英]ios: Where should I keep application data files, Temp or Document folder?

I'm building a video library application using Swift, I am wondering where to keep downloaded video files, is it better to use Document folder or just using the temp folder. 我正在使用Swift构建视频库应用程序,我想知道在哪里保存下载的视频文件,使用Document文件夹或仅使用临时文件夹更好。

let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
// OR
let documentsPath = NSTemporaryDirectory()

Thanks! 谢谢!

If want user to be able to access the videos from iTunes ( See here on how to do it ) than you should save videos in DocumentDirectory and if those videos are not that usefull and should be deleted than you can save them in NSTemporaryDirectory . 如果希望用户能够访问iTunes中的视频( 请参阅此处有关如何操作 ),而不是在DocumentDirectory中保存视频,如果这些视频不是那么有用且应该被删除,那么您可以将它们保存在NSTemporaryDirectory中。 It depends on how important are those videos in your app. 这取决于您的应用中这些视频的重要程度。

Videos in DocumentDirectory will be saved permanently while NSTemporaryDirectory can be cleared by OS when device is running short of memory as it is assumed that content in NSTemporaryDirectory is not that critical and should be redownloaded by app if needed DocumentDirectory中的视频将被永久保存,而当设备内存不足时,操作系统可以清除NSTemporaryDirectory,因为假设NSTemporaryDirectory中的内容不是那么关键,如果需要应该由应用程序重新下载

Also follow remember to follow this iOS Data Storage Guidelines guidelines and mark your files as "Do not backup" 另请注意记住遵循此iOS数据存储指南准则并将您的文件标记为“不备份”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM