【问题标题】:Schedule notification to execute every day starting next week安排通知从下周开始每天执行
【发布时间】:2016-11-24 17:49:45
【问题描述】:

我原来的问题:

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

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

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

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

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

示例:

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

谢谢。

【问题讨论】:

    标签: ios swift usernotifications unnotificationrequest unnotificationtrigger


    【解决方案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);
            }
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2021-07-26
      • 2015-04-12
      • 1970-01-01
      相关资源
      最近更新 更多