0

我想在每个月的最后一天 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?"];
4

1 回答 1

0

好吧,如果您希望在 12:00 触发通知,显然您应该将 Hour 设置为 12... 为什么不先尝试 Hours 或 Days。如果他们有效,那么本月也应该这样做。

于 2013-05-20T09:57:03.000 回答