必须为我的应用程序设置到期日期。目前,我正在存储打开应用程序的日期,代码如下所示
NSError *error;
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"ExpiredDate" inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
[fetchRequest setEntity:entityDesc];
NSArray *fetchedObjects = [[context executeFetchRequest:fetchRequest error:&error] retain];
[fetchRequest release];
if([fetchedObjects count ]<=0)
{
NSDate *todays=[[NSDate alloc]init];
NSDateFormatter *date=[[NSDateFormatter alloc]init];
[date setDateFormat:@"MM/DD/YYYY"];
[date stringFromDate:todays];
NSString *datelabel = [NSString stringWithFormat:@"%@",
[date stringFromDate:todays]];
NSManagedObject *objUser;
NSError *error;
objUser = [NSEntityDescription insertNewObjectForEntityForName:@"ExpiredDate" inManagedObjectContext:context];
[objUser setValue:datelabel forKey:@"date"];
if (![context save:&error])
{
NSLog(@"Problem saving: %@", [error localizedDescription]);
}
}
else
{
for(int i=0; i< [fetchedObjects count]; i++)
{
edate = [fetchedObjects objectAtIndex:i];
}
NSLog(@"%@",edate.date);
if(onemonth)
{
alertview:if one month completed then i have to show a pop up.please upgrade }
else
{
my code should execute
}
}
现在,我只想用当前日期计算一个月的日期(我已经存储并且我像字符串一样存储),如果超过一个月,那么我必须显示一个弹出窗口,比如请升级。