我想每个月的最后一天发送本地推送通知12.00。 我希望有人检查这是否是正确的代码,因为我不想等一个月看它是否有效?日Thnx!
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?"];
答案 0 :(得分:0)
嗯,显然你应该将小时设置为12,如果你想在12点解雇通知...... 为什么不先尝试小时或天。如果他们工作,本月也应该这样做。