0
目前在我的游戏中我有一个NSTimer,当点击一个按钮时,计时器从10分钟倒数到0。同时点击按钮UILocalNotification被触发,所以如果用户关闭应用程序,它会当10分钟达到0时发出消息。Xcode - 有没有办法在标签中表示UILocalNotification?
我的问题是,如果用户关闭应用程序,并在10分钟之前打开它或更改视图,则标签没有跟踪时间!
所以我的问题是我将如何有一个倒计时计时器,即使应用程序关闭/更改视图,并能够在标签中显示此计时器。
这是我为我的计时器代码:
- (IBAction)startTimer {
mainInt = 600;
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
- (void)countDown {
mainInt -= 1;
int seconds = mainInt % 60;
int minutes = (mainInt - seconds)/60;
timerLabel.text = [NSString stringWithFormat:@"%d:%.2d", minutes, seconds];
if (mainInt == 0) {
[timer invalidate];
}
}
代码设置UILocalNotification的:
- (IBAction)startTime {
UILocalNotification * theNotification = [[UILocalNotification alloc] init];
theNotification.alertBody = @"Alert text";
theNotification.alertAction = @"Ok";
theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:600];
[[UIApplication sharedApplication] scheduleLocalNotification:theNotification];
}
感谢您的帮助!