首页 文章

安排从下周开始每天执行的通知

提问于
浏览
0

My original problem:

当用户在19:00设置闹钟时,我想在19:03 19:09 19:12显示提醒,以防他没有与通知互动 .

(该应用程序应该能够脱机运行,因此无法使用推送通知来唤醒应用程序以进行此过程,如您所知,本地通知不会唤醒应用程序) .

因此,每次用户安排提醒时,我都会敏锐地安排4(1个原始和3个重复),如果用户与通知交互,我将删除所有其余的 .

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

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

EXAMPLE:

今天是星期日13:00我想在明天13:01开始每个星期天的通知 .

谢谢 .

1 回答

  • 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);
            }
        }];
    }
    

相关问题