0

我原来的问题:

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

(应用程序应该能够离线运行,因此在此过程中无法使用推送通知来唤醒应用程序,并且如您所知,本地通知不会唤醒应用程序)。

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

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

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

例子:

今天是星期日 13:00,我想从明天开始的每个星期日的 13:01 安排一个通知。

谢谢。

4

1 回答 1

-1

这是每天在同一时间收到通知的客观 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);
        }
    }];
}
于 2017-06-23T13:38:54.820 回答