Macos 通过在Nsdate中不考虑系统日期,将日期增加30天

Macos 通过在Nsdate中不考虑系统日期,将日期增加30天,macos,ios5,xcode4.2,nsdate,Macos,Ios5,Xcode4.2,Nsdate,我想在文件夹创建日期前添加30天,并在30天后阻止应用程序。 如果他们更改了系统日期,我的应用程序也应在计数后关闭 NSDateComponents *components; NSString *path = @"/Users/Syed/Library/Swasstik/KITSMAW0051_SWASSTIK_DB.sqlite"; BOOL isFile = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:N

我想在文件夹创建日期前添加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]);
请帮我解决这个问题。
提前谢谢

您可以尝试在系统上查找最近修改的文件(例如,用户首选项文件夹中的文件,因为这些文件经常被修改),并与修改日期进行比较。即使用户将其系统时间调回,以前修改过的文件也会保留更新的修改日期


如果用户在过去(如1990年)永久保留系统时间,那么这当然不起作用,但它将阻止用户尝试只返回使用应用程序的时间。我认为不太可能有人将系统时间永久错误,因为这真的很不方便。

我不明白你的问题是什么。如果你得到一个文件的创建日期,你可以将其与现在的时间进行比较。@codingFriend1我不想与系统日期进行比较。因为用户可以更改系统日期并使用我的应用程序。有没有其他方法可以做到这一点???例如在文件夹创建日期中添加30天计数。为什么要在创建日期中添加30天?但是,这当然可以使用NSFileManager的
setAttributes:ofItemPath:error:
方法,类似于您在上面代码中读取属性的方式。我想在30天后阻止应用程序,所以我想这样做。