【发布时间】:2014-07-22 11:56:52
【问题描述】:
如何将 UILocalNotification 设置为每两天、每三天等重复一次...?不使用默认的 NSCalendarUnits?
【问题讨论】:
标签: ios objective-c uilocalnotification nscalendar
如何将 UILocalNotification 设置为每两天、每三天等重复一次...?不使用默认的 NSCalendarUnits?
【问题讨论】:
标签: ios objective-c uilocalnotification nscalendar
两天之内不能重复,本地通知只允许4个重复间隔
按日、周、月或年,
它是一个枚举值,您可以自定义它,我看到的唯一解决方案是您计算时间差并比较两天时间,然后尝试再次设置它
【讨论】:
首先,我们必须设置我们的 NSDate,我们将在该日期上触发我们的第一个本地通知。 一旦通知被调用设置为下一个通知。
NSDate *afterTwoDays = [[NSDate date] dateByAddingTimeInterval:+2*24*60*60];
设置所需参数:
UILocalNotification *localNotification=[[UILocalNotification alloc]init];
localNotification.fireDate =afterTwoDays;
localNotification.alertBody = @"Body";
localNotification.alertAction = @"Alert";
localNotification.repeatInterval=0;
localNotification.soundName=UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
【讨论】: