0
我想從現在開始在2分鐘內觸發通知,並且還想每分鐘重複一次。下面的代碼的問題是它會在每分鐘內重複,但它會在2分鐘內立即啓動。感謝任何幫助。iOS 10通知觸發並重復每分鐘
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);
}];
這將在2分鐘內開始,但不會在每分鐘後重復。 – Viraj