我想在每个月的最后一天 12.00 发送本地推送通知。我希望有人检查这是否是正确的代码,因为我不想等一个月看看它是否有效?谢谢!
NSDate *curDate = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDate *fireTime;
[comps setMonth: [comps month] + 1];
[comps setDay: 0];
[comps setHour: 14];
[comps setMinute: 0];
NSDate *lastDayMonth = [calendar dateFromComponents:comps];
NSLog(@"%@", lastDayMonth);
fireTime = lastDayMonth;
localNotif.repeatInterval = NSMonthCalendarUnit;
localNotif.fireDate = fireTime;
localNotif.alertBody = [NSString stringWithFormat: @"working?"];