0

我原来的问题:安排通知执行每天从下周开始

当用户设定闹钟19:00,我想显示在一个提醒: 19:03 19: 09 19:12 如果他没有与通知进行交互。 (该应用程序应该能够离线运行,因此无法使用推送通知来唤醒该进程的应用程序,正如您所知,本地通知不会唤醒应用程序)。

因此,每次用户安排提醒时,我都会严格安排4(1个原创和3个重复),如果用户与通知进行交互,我会删除所有其他内容。

问题是,通知每天都会重复(每周1,2,3,4,5,6或7天)因此,如果我删除所有通知,它将不会再次显示。

有没有办法让通知每天从下周开始?

例:

今天是星期天13:00 我想时间表,每周日的通知上13:01从明天开始。

谢谢。

回答

0

这是一个客观的C代码,每天都在同一时间得到通知。 提供您当天安排通知的日期假设 6月23日上午8:30,然后它会在每天上午8:30安排通知。

-(void)scheduleNotificationAtTime:(NSDate *)date withUserInfo:(NSDictionary *)dictData{ 

     self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];; 
    NSDateComponents *components = [self.gregorian components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:date]; 

    NSDateComponents *components1 = components; 
    components1.hour = components.hour; 
    components1.minute = components.minute; 


    NSInteger hour = [components hour]; 
    NSInteger minute = [components minute]; 

    NSLog(@"Hour %ld Min %ld ", hour,minute); 


    UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components1 repeats:YES]; 

    /* Set notification */ 

    UNMutableNotificationContent *content = [UNMutableNotificationContent new]; 
    content.body = @"Yo received notification."; 
    // content.categoryIdentifier=NSNotificationC; 
    content.sound = [UNNotificationSound defaultSound]; 
    NSString *identifier = @"LocalNotification"; 
    content.userInfo = dictData; 
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier 
                      content:content 
                      trigger:trigger]; 

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
    center.delegate = self; 
    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { 
     if (error != nil) { 
      NSLog(@"Something went wrong: %@",error); 
     } 
    }]; 
} 
相关问题