【发布时间】:2012-10-10 12:15:45
【问题描述】:
我想在文件夹创建日期上增加 30 天,并在 30 天后阻止该应用程序。 如果他们更改系统日期,我的应用程序也应该在计数后关闭。
NSDateComponents *components;
NSString *path = @"/Users/Syed/Library/Swasstik/KITSMAW0051_SWASSTIK_DB.sqlite";
BOOL isFile = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NO];
if (isFile) {
NSLog(@"File exists");
NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate
NSLog(@"%@",result);
NSDate* date = [NSDate date];
NSLog(@"%@", [date description]);
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
components = [gregorianCalendar components:NSDayCalendarUnit
fromDate:result
toDate:date
options:0];
[gregorianCalendar release];
NSLog(@"%ld", [components day]);
请帮我解决这个问题。 提前致谢。
【问题讨论】:
-
我不明白你的问题是什么。如果您获得文件的创建日期,您可以将其与现在的时间进行比较。
-
@codingFriend1 我不想与系统日期进行比较。因为用户可以更改系统日期并使用我的应用程序。
标签: macos ios5 xcode4.2 nsdate