美文网首页
每个星期的星期几几点几分发起本地通知

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

作者: 一个默默无闻的程序猿 | 来源:发表于2022-07-26 15:51 被阅读0次
    - (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;
    }
    

    相关文章

      网友评论

          本文标题:每个星期的星期几几点几分发起本地通知

          本文链接:https://www.haomeiwen.com/subject/ciyzirtx.html