2日間ゴーグルした後、私は誰にとっても(私を除いて)明確であるかのように解決策を見つけることができませんでした!
私は必要です:
Alert.applicationIconBadgeNumber = x
通知が発生するたびにバックグラウンドで更新されるように、次の方法で通知を繰り返しています。
notif.repeatInterval = NSMinuteCalendarUnit
繰り返しは1mごとに正常に機能しています。アプリがバックグラウンドで実行されても、BadgeNumberが更新されると、最初に更新された日付の値のみが取得されます。
viewDidLoadでscheduleNotificationメソッドを呼び出しています
これが私の完全なコードです:
- (void)scheduleNotification {
UILocalNotification *notif;
notif = [[[UILocalNotification alloc] init] autorelease];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.fireDate = [[NSDate date] dateByAddingTimeInterval:5];
notif.repeatInterval = NSMinuteCalendarUnit;
NSInteger BadgeNumber = [self BadgeNumber];
NSInteger *BadgeNumberPointer = &BadgeNumber;
NSString *BadgeNumberString = [NSString stringWithFormat:@"%i", BadgeNumber];
notif.applicationIconBadgeNumber = *BadgeNumberPointer;
notif.alertBody = BadgeNumberString;
notif.alertAction = @"Hello";
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
-(int)BadgeNumber{
NSDate *currentDateUpdate = [[NSDate alloc] init];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"dd"];
NSString *dateCheckUpdate = [formatter2 stringFromDate:currentDateUpdate];
NSInteger dateCheckUpdateInt = [[dateCheckUpdate substringWithRange:NSMakeRange(0, 2)] integerValue];
int BadgeNumber = dateCheckUpdateInt;
return BadgeNumber;
}
修正方法を教えてください、皆さんに感謝します。