SHOW:
|
|
- or go back to the newest paste.
1 | -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
2 | { | |
3 | [self scheduleCheckTimer]; | |
4 | } | |
5 | - | -(void)applicationWillEnterForeground:(UIApplication *)application |
5 | + | |
6 | - | { |
6 | + | |
7 | - | if([NSDate date] compare: self.checkDate] == NSOrderedDescending) { |
7 | + | |
8 | - | [self checkTimerTimeout]; |
8 | + | |
9 | - | } else { |
9 | + | |
10 | - | [self scheduleCheckTimer]; |
10 | + | |
11 | - | } |
11 | + | |
12 | -(void) checkTimerTimeout | |
13 | { | |
14 | - | - (void)applicationDidEnterBackground:(UIApplication *)application |
14 | + | |
15 | [self scheduleCheckTimer]; | |
16 | } | |
17 | ||
18 | -(NSDate*) nextCheckDate { | |
19 | ||
20 | NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; | |
21 | ||
22 | NSDateComponents* dateComponents = [gregorian components: kCFCalendarUnitEra | | |
23 | - | self.checkDate = [self nextCheckDate]; |
23 | + | |
24 | kCFCalendarUnitMonth | | |
25 | kCFCalendarUnitDay | | |
26 | kCFCalendarUnitHour | | |
27 | kCFCalendarUnitMinute | | |
28 | kCFCalendarUnitSecond fromDate: [NSDate date]]; | |
29 | ||
30 | ||
31 | dateComponents.hour = 0; | |
32 | dateComponents.minute = 0; | |
33 | dateComponents.second = 0; | |
34 | dateComponents.day = dateComponents.day + 1; | |
35 | ||
36 | return [gregorian dateFromComponents: dateComponents]; | |
37 | } |