0

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

    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任何人都可以在这个问题上帮助我在应用程序中设置警报季度吗?

4

1 回答 1

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];
于 2013-05-28T13:56:25.083 回答