繁体   English   中英

UNMutableNotification 仅在工作日

[英]UNMutableNotification Only On Weekdays

我正在尝试在用户指定的时间触发本地通知,但仅在 MF 上。 如果我用.day任何内容,那么它将成功触发,但每周的每一天都这样做。 设置date.day = 2|3|4|5|6; 使它到达根本不会开火的地方。 想法?

UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
    content.title = [NSString localizedUserNotificationStringForKey:@"MY_STRING" arguments:nil];
    content.body = [NSString localizedUserNotificationStringForKey:@"MESSAGE"
            arguments:nil];
    content.categoryIdentifier = @"MY_ID";
    content.sound = [UNNotificationSound defaultSound];


    NSDateComponents* date = [[NSDateComponents alloc] init];
    NSDate *theTime = [pickADay date];
    NSCalendar *calendar = NSCalendar.currentCalendar;
    NSDateComponents *components = [calendar components: NSCalendarUnitHour | NSCalendarUnitMinute fromDate:theTime];
    date.hour = components.hour;
    date.minute = components.minute;
   
    date.day = 2|3|4|5|6;
    UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger
           triggerWithDateMatchingComponents:date repeats:YES];
     
    // Create the request object.
    UNNotificationRequest* request = [UNNotificationRequest
           requestWithIdentifier:@"DailyWord" content:content trigger:trigger];
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
       if (error != nil) {
           NSLog(@"%@", error.localizedDescription);
       }
    
    }];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM