4

以下のように複数のUNUsernotificationsを設定していますが、

- (void)viewDidLoad {
    [super viewDidLoad];
    notifCount = 0;
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              if (!error) {
                                  NSLog(@"request succeeded!");

                                  [self set10Notif];

                              }
                          }];
}

メソッドではset10Notif、現在の時刻から 10 秒後に複数 (テスト用に 8 つ) の通知を設定しています。

-(void) set10Notif
{
    notifCount = notifCount+1;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0") && notifCount < 10)
    {
        // create actions
      NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

      [calendar setTimeZone:[NSTimeZone localTimeZone]];

       NSDate *fireD = [[NSDate date] dateByAddingTimeInterval:notifCount*10];

       NSString *fireStr = [self returnStringFromDate:fireD withFormat:@"hh/mm/ss dd/MM/yyyy"];

       NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:fireD];

      UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];
    objNotificationContent.title = [NSString localizedUserNotificationStringForKey:@"Notif!" arguments:nil];
    objNotificationContent.body = [NSString localizedUserNotificationStringForKey:fireStr
                                                                        arguments:nil];
    objNotificationContent.sound = [UNNotificationSound defaultSound];

      UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];

      UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"Prayer"
                                                                          content:objNotificationContent trigger:trigger];
      UNUserNotificationCenter *userCenter = [UNUserNotificationCenter currentNotificationCenter];
      [userCenter addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
        if (!error) {

            NSLog(@"Local Notification succeeded");
        }
        else {
            NSLog(@"Local Notification failed");
        }
        [self set10Notif];
       }];
   #endif
    }
}

すべてのローカル通知が設定されています。しかし、デバイスで発生した通知は 1 つだけで、それが最後の通知です。

複数の通知が発生しないのはなぜですか? 私は何を間違えましたか?

4

2 に答える 2