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];
}
The File. lastModified read-only property provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With