【发布时间】:2012-11-25 18:17:43
【问题描述】:
我有一个应用程序可以下载每隔几个月更新一次的 PDF,每次下载某个 PDF 时,我还会下载一个包含一个字符的 .txt 文件。每次我在服务器上上传更新的 PDF 时,我也会将服务器上 .txt 文件中的字符数加一。
当用户在我的应用程序中点击“更新”按钮时,我会将来自服务器的 .txt 文件中的字符串与本地 .txt 文件的字符串进行比较。
这是一种非常轻量级的检查新 PDF 是否可用的方法,但我想问是否有更好的方法或更轻松的方法来执行此操作,而无需为我创建的每个 PDF 文件创建一个 .txt 文件我的服务器上有吗?
提前感谢您提供的任何帮助!
这是我用来检查新 PDF 的代码:
NSString *documentDirectory = [(AppDelegate *)[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"test.txt"];
NSString *server = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"foo.com/test.txt"] encoding:NSASCIIStringEncoding error:nil];
NSString *local = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil];
if(![local isEqualToString:server])
{
// I Download the new PDF and the new .txt file here;
// simple NSURLConnection stuff, no need to elaborate
}
【问题讨论】:
标签: objective-c ios nsstring nsfilemanager