我想在文件夹创建日期中添加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]);
请帮我解决这个问题。 提前致谢。
答案 0 :(得分:0)
您可以尝试在系统上找到最近修改过的文件(例如,一个来自用户的Preferences文件夹,因为这些文件经常被修改)并与该修改日期进行比较。即使用户返回系统时间,之前修改过的文件也会保留较新的修改日期。
如果用户在过去(例如1990年)永久保留系统时间,那当然不会起作用,但它会阻止尝试只转回使用你的应用程序的时间。我认为不太可能有人永久地将他的系统时间保持错误,因为这真的很不方便。