kCFCalendarUnitQuarter未设置每季度通知的下一个触发日期

时间:2013-05-28 12:08:29

标签: iphone ios

在我的应用程序中使用本地通知设置闹钟时,我遇到了问题。在我的应用程序中,我想设置一些警报每周触发,一些警报每天,一些警报每季度。已成功设置每日和每周警报,但未成功设置季度警报。我试过下面的代码来设置警报:

    if(buttonIndex == 0) { // Daily
        notification.repeatInterval = NSDayCalendarUnit;
    }else if(buttonIndex == 1) { // Weekly
        notification.repeatInterval = kCFCalendarUnitWeek;
    }else if(buttonIndex == 2) { // Monthly
        notification.repeatInterval = kCFCalendarUnitMonth;
    }else if(buttonIndex == 3) { // Quertly
        notification.repeatInterval = kCFCalendarUnitQuarter;
    }else if(buttonIndex == 4) { // Annually
        notification.repeatInterval = kCFCalendarUnitYear;
    }

    notification.fireDate = fireDate;
    notification.userInfo = info;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

编写完这段代码后,我调试了应用程序,并在调试器中记录了这些值。除了notification.repeatInterval = kCFCalendarUnitQuarter选项外,它会打印下一个开火日期的值。

iOS申请中每季度设置闹钟可以帮助我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

没有解决你的问题,但看起来好多了。尝试为眼睛编写好的代码。

       NSCalendarUnit unit;
    switch (buttonIndex)
    {
        case 0:
            unit = NSDayCalendarUnit;
            break;
        case 1:
            unit = kCFCalendarUnitWeek;
            break;
        case 2:
            unit = kCFCalendarUnitMonth;
            break;
        case 3:
            unit = kCFCalendarUnitQuarter;
            break;
        case 4:
            unit = kCFCalendarUnitYear;
            break;

        default:
        {
            NSLog(@"Ooops!");
            return;
        }
            break;
    }
    notification.fireDate = fireDate;
    notification.repeatInterval = unit;
    notification.userInfo = info;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];