重复间隔设置为每小时时,UILocalNotification应用程序崩溃

时间:2013-02-14 13:41:43

标签: iphone ios ipad uilocalnotification repeat

其他重复间隔工作正常,但是当我将通知设置为每小时重复且计时器关闭时,应用程序只会冻结,并且在我清除所有本地通知之前无法重新打开应用程序。

switch(repeatType) {
            case kRepeatHourly:
                notif.repeatInterval = NSHourCalendarUnit;
                break;
            case kRepeatDaily:
                notif.repeatInterval = NSDayCalendarUnit;
                break;
            case kRepeatWeekly:
                notif.repeatInterval = NSWeekCalendarUnit;
                break;
            case kRepeatMonthly:
                notif.repeatInterval = NSMonthCalendarUnit;
                break;
            case kRepeatAnnually:
                notif.repeatInterval = NSYearCalendarUnit;
                break;
            default:
                break;
        } 

1 个答案:

答案 0 :(得分:0)

- (void)scheduleNotification {

    [reminderText resignFirstResponder];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {

        UILocalNotification *notif = [[cls alloc] init];
        notif.fireDate = [datePicker date];
        notif.timeZone = [NSTimeZone defaultTimeZone];

        notif.alertBody = @"Did you forget something?";
        notif.alertAction = @"Show me";
        notif.soundName = UILocalNotificationDefaultSoundName;
        notif.applicationIconBadgeNumber = 1;

        NSInteger index = [scheduleControl selectedSegmentIndex];
        switch (index) {
            case 1:
                notif.repeatInterval = NSMinuteCalendarUnit;
                break;
            case 2:
                notif.repeatInterval = NSHourCalendarUnit;
                break;
            case 3:
                notif.repeatInterval = NSDayCalendarUnit;
                break;
            case 4:
                notif.repeatInterval = NSWeekCalendarUnit;
                break;
            default:
                notif.repeatInterval = 0;
                break;
        }

        NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
                                                forKey:kRemindMeNotificationDataKey];
        notif.userInfo = userDict;

        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
    }
}

有关详细信息,请下载源代码格式reference link here