如何每两周设置一次本地通知

时间:2016-08-10 10:18:48

标签: ios objective-c uilocalnotification localnotification

如何每两周触发一次本地通知?

我做的是:

UILocalNotification *localNotification = UILocalNotification.new;
localNotification.repeatInterval = 14;
localNotification.fireDate = [NSDate dateWithTimeInterval:10 sinceDate:notificationDate];
localNotification.alertBody = notificationMessage;
localNotification.alertAction = @"Open";
localNotification.category = @"default_category";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

2 个答案:

答案 0 :(得分:1)

尝试以下代码:

UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.userInfo = @{@"notification_identifier":@"After14Days"};
notification.fireDate = [[NSDate date] dateByAddingTimeInterval:(60*60*24*14)];
notification.alertBody = @"Text to display";
notification.repeatInterval = NSCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

答案 1 :(得分:0)

将UILocalNotification的repeatInterval设置为NSCalendarUnitDay。