我的应用程序数据中有一个 plist 文件,我想每 24 小时从网络服务器更新一次。有没有办法检查文件的最后修改时间,或者我应该以某种方式注册更新文件的日期和时间,并用它来比较?
if (lastMod > currentDate){
[arrayFromXml writeToFile:path atomically:YES];
}
最佳答案
您可以为此使用 NSFileManager:
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:@"path/to/my/file" error:nil];
NSDate *date = [attributes fileModificationDate];
// compare 'date'
// date > now
if ([date compareTo:[NSDate date]] == 1)
{
[arrayFromXML writeToFile:@"path/to/my/file" atomically:YES];
}
关于iphone - 获取应用程序数据文件的最后文件修改日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365355/