카운트 다운 타이머가 있습니다. 응용 프로그램을 종료하고 다시 실행하면 타이머는 할당 된 시간에 따라 시간을 재개해야합니다. 가능한가?응용 프로그램을 종료하고 다시 실행하십시오. 타이머는 할당 된 시간에 따라 시간을 재개해야합니다.
timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(timerFired)
userInfo:nil repeats:YES];
- (void)timerFired
{
if((currMinute>0 || currSeconds>=0) && currMinute>=0)
{
if(currSeconds==0)
{
currMinute-=1;
currSeconds=59;
}
else if(currSeconds>0)
{
currSeconds-=1;
}
if(currMinute>-1)
timeRemain=[NSString stringWithFormat:@"%d%@%02d",currMinute,@":",currSeconds];
}
else
{
[timer invalidate];
}
}
앱을 종료 할 때 'UserDefaults' 남은 시간을 저장 한 다음 앱이 다시 시작될 때 해당 값을 읽습니다. 그런 다음 남은 시간을 계속할 수 있습니다. 계속해서 카운팅하는 것처럼 행동하기를 원한다면 앱을 종료하고 UserDefaults를 종료 한 다음 현재 시간을 기준으로 계산을하고 싶을 것입니다. – Hodson