其實你可以,
首先,對於「startTimeOfMyExoticTimer」創建默認值NSUserDefaults的:
[[[NSUserDefaults] standardDefaults] setObject:[NSDate date] forKey:@"startTimeOfMyExoticTimer"];
然後檢查一個定時器的踢,如果有效時間範圍是在:
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(checkIfTimeIsOver) userInfo:nil repeats:YES];
然後實現你的檢查方法:
-(void)checkIfTimeIsOver{
NSDate * now = [NSDate date];
NSDate * startTime = [[NSUserDefaults standardDefaults] objectForKey:@"startTimeOfMyExoticTimer"];
// Here compare your now and startTime objects. (subsract them) and see the difference between them. If your time range is to be set on 30 seconds. Then you should check if the time difference between those objects are bigger than 30 seconds.
}
這將是工作,即使設備處於鎖定狀態,應用程序是在後臺等
這種方式爲我工作,希望它會爲你工作太
什麼行動?你只是想通知用戶,然後執行行動,如果他們接受通知? – Wain