Iphone 如何创建每两分钟通知一次的UILocalNotification

Iphone 如何创建每两分钟通知一次的UILocalNotification,iphone,ipad,Iphone,Ipad,因此,我基本上是在尝试设置一个能够不断提供本地通知的应用程序 到目前为止,我已经: - (void)scheduleNotification { [reminderText resignFirstResponder]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; Class cls = NSClassFromString(@"UILocalNotification"); if

因此,我基本上是在尝试设置一个能够不断提供本地通知的应用程序

到目前为止,我已经:

- (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 = @"Your building is ready!";
        notif.alertAction = @"View";
        notif.soundName = UILocalNotificationDefaultSoundName;
        notif.applicationIconBadgeNumber = 1;

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

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

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

我正在尝试这样做,以便每2分钟(设置案例2时)和每1分钟(设置案例1时)收到通知。唯一的问题是。。。*2无法使其每2分钟收到一次通知。我该如何做才能让它每2分钟通知一次

设置UILocalNotification的repeatInterval属性时,只能使用NSCalendarUnit中定义的日历单位。无法使用自定义单位或操纵单位,因此无法使用通知的“重复间隔”属性执行所需操作

要每2分钟安排一次通知,您很可能希望在不同的时间(间隔2分钟)安排多个通知。您可以创建UILocalNotification,然后使用以下内容计划它:

[[UIApplication sharedApplication] scheduleLocalNotification: localNotification];
然后修改fireDate属性(通过添加重复间隔),然后使用相同的代码再次安排它。您可以在循环中重复此操作,无论您需要重复通知多少次