오늘의 위젯에서 카운트 다운되는 타이머가 있습니다. 내 View Controller에서 날짜를 모으고 확장 프로그램에서 타이머를 시작하고 거기에서 날짜를 세 개의 레이블 인 Hours, Minutes, Seconds로 표시합니다. 내 응용 프로그램에서는 ... 완벽하지만 알림 센터에서는 그렇지 않습니다. 카운트 다운이 올바르게로드되고 약 20 초 동안 훌륭하게 작동합니다. 그 다음 초를 건너 뛰고 정지 한 다음 약 4 초 후에 다시 시작하고 전체 위젯을 다시 설정합니다 (모든 것이 사라짐). 약 2 초 후 전체 위젯이 재설정됩니다. 이것은 메모리 경고인가요?오늘 연장의 타이머 연장 연장이 동결 됨
보기 컨트롤러 : mainTextLabel.text = 436,496,400
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.nicmac.nextgame"];
[sharedDefaults setObject:mainTextLabel.text forKey:@"MyNumberKey"];
[sharedDefaults synchronize];
오늘보기 컨트롤러
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.preferredContentSize = CGSizeMake(320, 300);
[self performSelector:@selector(updateNumberLabelText) withObject:nil afterDelay:1.0];
}
- (void)userDefaultsDidChange:(NSNotification *)notification {
[self performSelector:@selector(updateNumberLabelText) withObject:nil afterDelay:1.0];
}
- (void)updateNumberLabelText {
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.nicmac.nextgame"];
NSString *date = [defaults stringForKey:@"MyNumberKey"];
self.numberLabel.text = [NSString stringWithFormat:@"%@", date];
NSString *doubleString = self.numberLabel.text;
double value = [doubleString doubleValue];
destinationDate = [NSDate dateWithTimeIntervalSince1970:value];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateNumberLabelText) userInfo:nil repeats:YES];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
int units = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[hour setText:[NSString stringWithFormat:@"%ld", (long)[components day] * 24 + (long)[components hour]]];
[minute setText:[NSString stringWithFormat:@"%ld", (long)[components minute]]];
[second setText:[NSString stringWithFormat:@"%ld", (long)[components second]]];
}
감사합니다!