私は多くのコードを見ましたが、まだ解決策が得られませんでした.
アプリのアイコンバッジを毎日更新し、その日のカレンダー (グレゴリオ暦ではない) 番号を取得する必要があります。
どうやってやるの?
私は多くのコードを見ましたが、まだ解決策が得られませんでした.
アプリのアイコンバッジを毎日更新し、その日のカレンダー (グレゴリオ暦ではない) 番号を取得する必要があります。
どうやってやるの?
あなたがそれをどのようにコーディングするかはわかりませんが、そのようなアプリをアプリ ストアに提出しようとしても、アップルはそれを承認しません。Apple の厳格なレビュー ガイドラインはイライラする可能性があり、この場合のように、アプリの機能が制限されます。ごめん :(
アプリケーション バッジ番号を指定する必要があるため、繰り返しローカル通知を使用できないことは明らかです。したがって、午前 0 時にスケジュールされ、適切なバッジ番号を使用して、毎日 1 つのローカル通知を使用する必要があります。
最大 64 個のローカル通知しかスケジュールできないため、アプリケーションを起動するたびに通知をキューに入れる必要があります。
このコードはテストされていません。夏時間などに問題がある可能性があります。 (iOS 4.2 以降、ARC を使用して動作)
- (void) applicationDidBecomeActive:(UIApplication *)application {
NSUInteger startingDayAfterToday = [application.scheduledLocalNotifications count];
NSArray *localNotifications = [self localNotificationsStartingOnDayAfterToday:startingDayAfterToday];
NSArray *newScheduledNotifications = [application.scheduledLocalNotifications arrayByAddingObjectsFromArray:localNotifications];
[application setScheduledLocalNotifications:newScheduledNotifications];
}
- (NSArray *) localNotificationsStartingOnDayAfterToday:(NSUInteger)startingDayAfterToday {
NSMutableArray *localNotifications = [[NSMutableArray alloc] initWithCapacity:64 - startingDayAfterToday];
for (NSUInteger i = startingDayAfterToday; i < 64; i++) {
// Create a new local notification
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.hasAction = NO;
// Create today's midnight date
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; // Could be other calendar, too
NSDateComponents *todayDateComponents = [calendar components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
NSDate *todayMidnight = [calendar dateFromComponents:todayDateComponents];
// Create the fire date
NSDateComponents *addedDaysComponents = [[NSDateComponents alloc] init];
addedDaysComponents.day = i;
NSDate *fireDate = [calendar dateByAddingComponents:addedDaysComponents toDate:todayMidnight options:0];
// Set the fire date and time zone
notification.fireDate = fireDate;
notification.timeZone = [NSTimeZone systemTimeZone];
// Set the badge number
NSDateComponents *fireDateComponents = [calendar components:NSDayCalendarUnit fromDate:fireDate];
notification.applicationIconBadgeNumber = fireDateComponents.day;
// We're done, add the notification to the array
[localNotifications addObject:notification];
}
return [localNotifications copy];
}