获取应用程序数据文件的上次文件修改日期? [英] Get last file modification date of application data files?

查看:189
本文介绍了获取应用程序数据文件的上次文件修改日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序数据中有一个plist文件,我想从网络服务器每24小时更新一次。有一种方法来检查文件的最后修改或应该,在某种程度上注册日期和时间,当我更新文件,并用它来比较?

I have a plist file in my application data that i want to update from a webserver every 24 hours. Is there a way to check when the file is last modified or should i, in some way register the date and time when i update the file, and use that to compare to?

if (lastMod > currentDate){
    [arrayFromXml writeToFile:path atomically:YES];
}


推荐答案

您可以使用NSFileManager :

You can use NSFileManager for this:

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];
}

这篇关于获取应用程序数据文件的上次文件修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆