如何解决仅在工作日的 UNMutableNotification
我试图让本地通知在用户指定的时间触发,但仅限于 M-F。如果我省略了 .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);
}
}];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。