【问题标题】:Local push notification last day of month每月最后一天的本地推送通知
【发布时间】:2013-05-11 06:45:06
【问题描述】:

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

【问题讨论】:

    标签: nsdate uilocalnotification nscalendar nsdatecomponents


    【解决方案1】:

    好吧,如果您希望在 12:00 触发通知,显然您应该将 Hour 设置为 12... 为什么不先尝试几小时或几天。如果它们有效,那么本月也应该有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多