简体   繁体   English

iOS知道文件何时更改

[英]iOS know when file has changed

I am downloading a mp4 file with my iOS app, it works fine using 我正在使用我的iOS应用程序下载mp4文件,它可以正常使用

NSData dataWithContentsOfURL NSData dataWithContentsOfURL

but i need to updated only if the file has been updated, 但我只有在文件更新后才需要更新,

can I check the file headers? 我可以检查文件头吗? or what is the best way to determine if the file has been updated so I downloaded it again? 或者确定文件是否已更新的最佳方法是什么,以便我再次下载?

Thanks 谢谢

You can access the metadata using the http HEAD request, as explained in this SO answer . 您可以使用http HEAD请求访问元数据,如本SO答案中所述 You'll need to create some sort of parser to pick out the information you need, though. 但是,您需要创建某种解析器来选择所需的信息。 Note that this might not work with every server, depending on how it has been set up. 请注意,这可能不适用于每台服务器,具体取决于它的设置方式。

If you have control of the server yourself, I'd recommend using a php script to output the date the file has been last changed, which you would call before downloading the file. 如果您自己控制服务器,我建议您使用php脚本输出上次更改文件的日期,然后在下载文件之前调用该日期。

Personally, I prefer placing a manifest file (usually a plist) alongside the file in question, as it can hold even more data, for example metadata for several files, the number of entries in a database and the like. 就个人而言,我更喜欢将清单文件(通常是plist)放在有问题的文件旁边,因为它可以容纳更多数据,例如几个文件的元数据,数据库中的条目数等。 A backdraw of this approach is that you'll need to keep this file up to date, though. 这种方法的退款是你需要保持这个文件是最新的。 But often, that is worth the while. 但通常,这是值得的。

Lastly, as rckoenes has mentioned, dataWithContentsOfURL is not a very good way to download files, espcially large ones. 最后,正如rckoenes所提到的,dataWithContentsOfURL并不是一种非常好的下载文件的方法,特别是大文件。 You really should be using some sort of datamanager class, which manages a NSURLConnection . 你真的应该使用某种datamanager类来管理NSURLConnection

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

相关问题 iOS-知道何时更新PHP JSON文件 - iOS - know when PHP JSON file has been updated iOS:如何知道何时更改设备语言? - iOS : How to know when device language got changed? iOS 5中的scrollviewTexturedBackgroundColor是否已更改? - Has the scrollviewTexturedBackgroundColor changed in iOS 5? 当为iOS选择TableView单元格时,视图已更改 - View has changed when a TableView cell is selected for iOS 需要知道用户何时在iOS中单击键盘上的“返回” - Need to know when user has clicked 'return' on keypad in iOS 是否有可能知道用户何时在iOS 7中购买了我的其他应用程序? - Is it possible to know when a user has purchased my other apps in iOS 7? IOS swift如何知道activityViewController何时成功使用 - IOS swift how to know when activityViewController has been successfully used iOS - 了解模态视图何时被解除 - iOS - Know when modal view has been dismissed 如何知道用户是否更改了标签? - How to know if a user has changed tab? 如何确定来自移动客户端(例如iOS)的S3存储桶上的文件是否已更改 - How to determine if file has changed on the S3 bucket from a mobile client (e.g. iOS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM