當(dāng)前時間大于等于預(yù)定時間,即請求下面接口,反之請求另外接口,代碼貼在下面,粘貼上自己代碼就可以使用:

- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? NSDate*currentDate = [NSDatedate];
? ? NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
? ? [dateFormattersetDateFormat:@"YYYY-MM-dd"];
? ? NSString* currentDateStr = [dateFormatterstringFromDate:currentDate];
? ? intcomparisonResult = [selfcompareDate:currentDateStrwithDate:@"自己定義個時間"];
? ? if(comparisonResult >0){
? ? ? ? //endDate 大
? ? ? ? [self jsusWebView];
? ? }else{
? ? ? ? [self requestMainURL];
? ? }
? ? // Do any additional setup after loading the view from its nib.
}
//比較兩個日期大小
-(int)compareDate:(NSString*)startDate withDate:(NSString*)endDate{
? ? intcomparisonResult;
? ? NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
? ? [formattersetDateFormat:@"yyyy-MM-dd"];
? ? NSDate *date1 = [[NSDate alloc] init];
? ? NSDate *date2 = [[NSDate alloc] init];
? ? date1 = [formatterdateFromString:startDate];
? ? date2 = [formatterdateFromString:endDate];
? ? NSComparisonResultresult = [date1compare:date2];
? ? NSLog(@"result==%ld",(long)result);
? ? switch(result)
? ? {
? ? ? ? ? ? //date02比date01大
? ? ? ? case NSOrderedAscending:
? ? ? ? ? ? comparisonResult =1;
? ? ? ? ? ? break;
? ? ? ? ? ? //date02比date01小
? ? ? ? case NSOrderedDescending:
? ? ? ? ? ? comparisonResult = -1;
? ? ? ? ? ? break;
? ? ? ? ? ? //date02=date01
? ? ? ? case NSOrderedSame:
? ? ? ? ? ? comparisonResult =0;
? ? ? ? ? ? break;
? ? ? ? default:
? ? ? ? ? ? NSLog(@"erorr dates %@, %@", date1, date2);
? ? ? ? ? ? break;
? ? }
? ? returncomparisonResult;
}