4

好的,所以我看到几篇帖子说您不能将 a 设置UILocalNotification为重复多个或少于几个给定选项(每分钟/小时/天/周/月等)。

但是,这些帖子都没有解决设置 to 的属性repeatInterval会做什么。UILocalNotificationNSWeekdayCalendarUnit

我对所有这些 NSDate 和 NSCalendar 的东西都很陌生,所以我确定我遗漏了一些东西,但我已经阅读了文档,听起来你NSWeekdayCalendarUnit可以NSLocalNotification重复说,每周一、周二和周四,如果NSWeekdayCalendarUnit设置为 2,3,5。

NSWeekdayCalendarUnit 指定工作日单位。对应的值是一个 int。等于 kCFCalendarUnitWeekday。工作日单位是数字 1 到 N(对于公历 N=7,1 是星期日)。

这不正确吗?

提前致谢。

4

1 回答 1

1

是的你可以。我这样做。用户可以选择带有选择器的方案。然后选择以下方法:

- (void)setOneLocalAlarmNotification: (NSDate *)firstFireDate withRepeat: (NSInteger)repeat {

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = firstFireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];

switch(repeat) {
    case 0: 
        break ;
    case 1: 
        localNotif.repeatInterval = kCFCalendarUnitDay;
        break;
    case 2: 
        localNotif.repeatInterval = kCFCalendarUnitWeekday;
        break;
    default: 
        break;
}

// Notification details
localNotif.alertBody = @"Message?";
// Set the action button
localNotif.alertAction = @"Yes";

localNotif.soundName = @"glas.caf"; //UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

// Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:@"type"];
   localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release]
}
于 2011-03-24T21:24:24.130 回答