在userNotification中重复间隔问题

时间:2017-08-21 12:09:46

标签: ios objective-c notifications schedule unusernotificationcenter

我正在处理提醒应用。例如。如果我将05:25的时间安排在每2小时重复一次,则会在每2小时的时间间隔提醒,但是在当前时间没有提醒,即05:25。

UNMutableNotificationContent *localNotification = [UNMutableNotificationContent new];
localNotification.title = [NSString localizedUserNotificationStringForKey:@"Reminder!" arguments:nil];
localNotification.body = [NSString localizedUserNotificationStringForKey:_getReminderName arguments:nil];
localNotification.sound = [UNNotificationSound defaultSound];

UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60*60*2 repeats:YES];


UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:_getReminderName content:localNotification trigger:trigger];

request = [UNNotificationRequest requestWithIdentifier:_getReminderName content:localNotification trigger:trigger];
/// 3. schedule localNotification
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
    if (!error) {
         NSLog(@"add NotificationRequest succeeded!");
    }
}];

1 个答案:

答案 0 :(得分:0)

你应该在triggerWithTimeInterval上写下你的时间

    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval: 05:25 repeats:YES];

这里 05:25 应该是约会日期。

为了您的信息,您无法自定义重复时间间隔,您必须使用NSCalendarUnit的值

How to set repeat frequency in User Notification

如果我错了,请清除我。