0
我只想知道如何做一個平均或一天倒計數?我做了一些搜索谷歌,但我得到了一些信息,使這個應用程序,他們告訴我應該使用NSDate和NSCalendar.however我想存儲所有信息和用戶可以加載時重新打開應用程序,我應該使用SQLite或核心數據?感謝iphone倒數事件
我只想知道如何做一個平均或一天倒計數?我做了一些搜索谷歌,但我得到了一些信息,使這個應用程序,他們告訴我應該使用NSDate和NSCalendar.however我想存儲所有信息和用戶可以加載時重新打開應用程序,我應該使用SQLite或核心數據?感謝iphone倒數事件
奔,
1. Store your time (NSDate) at the appropriate time.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSDate date] forKey:@"CheckedInTime"];
[defaults synchronize];
當你的應用變得活躍起來: (IE) -
(無效)applicationDidBecomeActive:(UIApplication的*)應用
啓動計時器檢查時間是否已過期:
self.checkinTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(checkinTimerCheck:) userInfo:nil repeats:YES];
- (void) checkinTimerCheck:(NSTimer *) timer {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate * checkinTime = [defaults objectForKey:@"CheckedInTime"];
float hours = HOWEVER_MANY_HOURS_NEED_TO_PASS_TO_EXPIRE_IN_SECONDS;
if (hours < 0) {
[self alertUserThatTimeHasExpired];
}
}
無效計時器檢查時,您的應用程序變得
- (void)applicationWillResignActive:(UIApplication *)application
問候,
肯