我想从现在开始在 2 分钟内触发通知,并且还想每分钟重复一次。以下代码的问题是它会每分钟重复一次,但不会在 2 分钟内立即启动。感谢任何帮助。
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"Good morning";
content.body = @"Body";
content.sound = [UNNotificationSound defaultSound];
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:120];
NSDateComponents *triggerDate = [[NSCalendar currentCalendar]
components:NSCalendarUnitSecond fromDate:date];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:triggerDate repeats:YES];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"notification.daily" content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
NSLog(@"Error:%@", error);
}];