문제

I want to send local notification every minute and this is code that I'm using:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *notif = [[UILocalNotification alloc] init];

    if (notif == nil) {
        return;
    }

    notif.timeZone = [NSTimeZone defaultTimeZone];

    notif.alertBody = @"Test notification!";
    notif.alertAction = @"View";
    notif.soundName = UILocalNotificationDefaultSoundName;
    notif.applicationIconBadgeNumber += 1;

    notif.repeatInterval = NSMinuteCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];

The notification starts only once and never is repeated. Where I make mistakte?

도움이 되었습니까?

해결책

You have to set a fireDate for your notification, otherwise it won't repeat but fire instantly.

The fire date is interpreted according to the value specified for timeZone. If the specified value is nil or is a date in the past, the notification is delivered immediately.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top