每个星期的星期几几点几分发起本地通知

- (UNNotificationRequest *)createNotificationRequestWithWeekday:(NSInteger)weekday
                                                       withHour:(NSInteger)hour
                                                      witMinute:(NSInteger)minute
                                                     identifier:(NSString *)identifier
                                                      withTitle:(NSString *)title
                                                    withContent:(NSString *)contentStr{
    // 1.创建通知内容
    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
    content.sound = [UNNotificationSound defaultSound];
    content.title = title;
    content.body = contentStr;
    //content.badge = @(++kApplication.applicationIconBadgeNumber); // 不显示角标
    content.userInfo = @{@"kLocalNotificationID":kLockInNotification,@"identifier":identifier};
    // 2.触发模式 几点几分 每周重复 ()
    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    dateComponents.hour = hour; 
    dateComponents.minute = minute;
    dateComponents.weekday = weekday;
    UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
    // 4.设置UNNotificationRequest
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
    return request;
}

你可能感兴趣的:(每个星期的星期几几点几分发起本地通知)