UILocalNotifications 使用 NSWeekdayCalendarUnit 重复间隔

发布于 2024-10-20 08:07:00 字数 588 浏览 3 评论 0原文

好的,所以我看到几篇文章说你不能设置 UILocalNotification 来重复超过或少于几个给定的选项(每分钟/小时/天/周/月等)。

但是,这些帖子都没有解决将 UILocalNotificationrepeatInterval 属性设置为 NSWeekdayCalendarUnit 的作用。

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

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

这不正确吗?

提前致谢。

OK, so I have seen several posts that say you cannot set a UILocalNotification to repeat any more or less than a few given options (every minute/hour/day/week/month etc.).

However, none of those posts addressed what setting the repeatInterval property of UILocalNotification to NSWeekdayCalendarUnit would do.

I'm very new to all this NSDate and NSCalendar stuff, so I am sure I am missing something, but I have read over the documentation and, it sounds like you CAN use NSWeekdayCalendarUnit to make a NSLocalNotification repeat say, every Monday, Tuesday and Thursday if NSWeekdayCalendarUnit is set to 2,3,5.

NSWeekdayCalendarUnit
Specifies the weekday unit.
The corresponding value is an int. Equal to kCFCalendarUnitWeekday. The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday).

Is that not correct?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2024-10-27 08:07:00

是的,你可以。我就是这样做的。用户可以使用选择器选择方案。然后选择进入以下方法:

- (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]
}

Yes you can. I do it like this. The user can choose a scheme with a picker. And then the choice goes to the following method:

- (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]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文