UILocalNotification repeatInterval

1 objective-c uilocalnotification

我有两个问题.

  1. 如果我理解本地通知,则重复间隔允许我安排一次通知,并且每周或每月或每周的同一时间间隔重复通知.我想在星期二开始重复一次重复间隔,每周它会在同一天即星期二再次开火.这应该每周进行,而无需安排另一个通知.那是对的吗.是不是发生了.我要么在代码中做错了,要么我测试错了.

  2. 在模拟器中,我运行app安排通知.我看到了通知.然后我退出应用程序并在未来的同一天将系统日期设置为1周但没有通知,因此我可以通过更改计算机系统时钟以这种方式测试此通知.我不想每个测试都要等一个星期.

这是代码

- (void) scheduleNotificationWithItem:(NSDate *)date interval:(int)frequency {
 UILocalNotification *localNotif = [[UILocalNotification alloc]init];

 if (localNotif == nil) {
      return;
 }

 localNotif.fireDate = [date addTimeInterval:frequency];
 localNotif.timeZone = [NSTimeZone defaultTimeZone];
 localNotif.repeatCalendar = [NSCalendar currentCalendar];
 localNotif.repeatInterval = kCFCalendarUnitWeekday;
 localNotif.applicationIconBadgeNumber = 1;
 localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@.",nil),@"Weekly Reminder"];
 localNotif.alertAction = NSLocalizedString(@"View Notification Details", nil);
 localNotif.soundName = UILocalNotificationDefaultSoundName;

 [[UIApplication sharedApplication]scheduleLocalNotification:localNotif];

 [localNotif release];
}
Run Code Online (Sandbox Code Playgroud)

请帮助这让我发疯.谢谢,迪恩

ooj*_*joe 6

1)将重复间隔设置为'NSWeekCalendarUnit'应该可以解决问题.它在与原始通知相同的日期和时间每周重复一次.

2)我没有在模拟器中测试过,但在实际的iPhone上更改时钟确实会触发未来的警报.