将“真实日期”转换为 iOS 上位置通知的火灾日期字符串



让我再试一次,说得更清楚,我很抱歉。 \我正在考虑尝试在iOS中向我的照片分配应用程序添加特定于日期的提醒。我希望能够拥有它,这样它就会在一年中的确切日期触发提醒,将他们定向到一年中那个时候的作业

例如:

12月31日-除夕-发射烟花,派对7月1日-加拿大日拍摄庆典,烟花10月30日-万圣节前拍摄南瓜,服装12月15日-圣诞灯饰!

等。

我已经设置了一个每日提醒,每天

上午 9 点触发,提醒他们获得作业,该作业通过设置捆绑包中的切换开关根据用户的意愿打开或关闭。我希望有另一个用于"假期提醒"

这是我当前每日提醒的代码:

NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
                                                       fromDate:currentDate];
        NSDateComponents *temp = [[NSDateComponents alloc]init];
        [temp setYear:[dateComponents year]];
        [temp setMonth:[dateComponents month]];
        [temp setDay:[dateComponents day]];
        [temp setHour: 9];
        [temp setMinute:00];
        NSDate *fireTime = [calender dateFromComponents:temp];
        [temp release];
        // set up the notifier 
        UILocalNotification *localNotification = [[UILocalNotification alloc]init];
        localNotification.fireDate = fireTime;
        localNotification.timeZone = [NSTimeZone defaultTimeZone];

如何将实际日期(12 月 31 日)隐藏为 fireDate = 变量/字符串?

我希望这一点更加清楚。 我已经搜索过了,但无法找到答案。谢谢

诺埃尔·切尼尔

您只需要在创建 fireTime 时手动指定年、月和日。

NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
                                                   fromDate:currentDate];
    NSDateComponents *temp = [[NSDateComponents alloc]init];
    [temp setYear:2013];
    [temp setMonth:12];
    [temp setDay:31];
    [temp setHour: 9];
    [temp setMinute:00];
    NSDate *fireTime = [calender dateFromComponents:temp]; // December 31st 2013 9:00
    [temp release];
    // set up the notifier 
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];
    localNotification.fireDate = fireTime;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];

最新更新