0

I am working on the reminder app. For eg. if I set the timings of 05:25 scheduling it to repeat at every 2 hours, it is reminded at the interval of every 2 hours but it doesn’t remind at the current time i.e. 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!");
    }
}];
Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55
ikbal
  • 1,114
  • 1
  • 11
  • 30

1 Answers1

0

You should write your time on triggerWithTimeInterval like

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

Here 05:25 should be date formate.

And for your information you can't do customize repeat time interval you must use value of NSCalendarUnit like

How to set repeat frequency in User Notification

If I'm wrong then clear me.

Govaadiyo
  • 5,644
  • 9
  • 43
  • 72
  • then how can i set schedule for every two hours (triggerWithTimeInterval:60*60*2) – ikbal Aug 21 '17 at 12:18
  • NSCalendarUnitHour is set only for every one hour i want get notification every two hour. – ikbal Aug 21 '17 at 12:21
  • Yes you can't customize it like 2 hours – Govaadiyo Aug 21 '17 at 12:22
  • i already customise and it works properly but my main problem is i want to get notification from date picker date and time and also repeat after fire date – ikbal Aug 21 '17 at 12:26
  • If you want to repeat like every 3 min. or 2 hours then dam sure Apple does not provide any property or API so you can set your repeat time there. – Govaadiyo Aug 21 '17 at 12:38