【发布时间】:2011-05-09 14:46:38
【问题描述】:
我想将 UILocalNotification 的重复间隔自定义为一周中的某些天。我没有找到任何相关信息。
如何设置一周中某些天的通知重复间隔,例如,在星期日、星期一和星期五重复通知?
【问题讨论】:
-
我也有同样的问题
标签: ios cocoa-touch uilocalnotification
我想将 UILocalNotification 的重复间隔自定义为一周中的某些天。我没有找到任何相关信息。
如何设置一周中某些天的通知重复间隔,例如,在星期日、星期一和星期五重复通知?
【问题讨论】:
标签: ios cocoa-touch uilocalnotification
很遗憾,您不能将UILocalNotification 的repeatInterval 属性设置为仅在特定日期重复。您可以设置每天(每天)、每月(每个月)或每小时(每小时)重复。因此,对于您的问题,唯一可行的解决方案是,如果您想在周日、周一和周二设置闹钟,那么您必须设置 3 个闹钟(周日、周一和周二各一个),而不是一个闹钟。
【讨论】:
如果您需要自定义repeatInterval 属性。您必须在指定时间设置每个UILocalNotification。这是我的代码。
void (^insertAlarm)(NSDate*fire,NSString*sound,int alarmCount) = ^(NSDate*fire,NSString*sound,int alarmCount){
UILocalNotification* notification = [[UILocalNotification alloc] init];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = sound;
notification.fireDate = fire;
notification.repeatInterval = 0;
notification.alertLaunchImage = IMG;
notification.alertAction = ACTION_MSG;
notification.alertBody = BODY;
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
};
insertAlarm(date,sound.fileName,0);
insertAlarm([date dateByAddingTimeInterval:60],sound.fileName,1);
【讨论】: