我想每分钟发送一次本地通知,这是我正在使用的代码:
[[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];
通知只开始一次,永远不会重复。我哪里弄错了?
最佳答案
您必须为您的通知设置一个fireDate
,否则它不会重复而是立即触发。
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.
关于iphone - UILocalNotification 每分钟重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13490573/