The best solution would be: using the day of the week index to determine your URL:
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]]; NSInteger weekday = [components weekday]; NSString *urlString; switch(weekday){ case 1: // sunday urlString = @"http://google.com"; break; case 2: urlString = @"http://twitter.com"; break; case 3: urlString = @"http://facebook.com"; break; case 4: urlString = @"http://yahoo.com"; break; case 5: urlString = @"http://mashable.com"; break; case 6: urlString = @"http://bbc.co.uk"; break; case 7: // saturday urlString = @"http://stackoverflow.com"; break; default: urlString = @"http://google.com?q=weekday+is+never+this!"; break; } NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [webview loadRequest:requestObj];
To update your checks, as you requested in the comment, you can do this:
In the application delegation file, add this line to applicationDidBecomeActive: method
- (void)applicationDidBecomeActive:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDateCheck" object:nil]; }
In your class, you are checking the date; in the init method, add this line to listen for any update notifications sent when the application exits the background:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:@"refreshDateCheck" object:nil];
Finally, follow the date verification code to this method, which is called whenever a notification is received:
-(void)myMethod{ }
source share