ios – UILocalNotification应该每个工作日重复,但周末也会发生

ios – UILocalNotification应该每个工作日重复,但周末也会发生,第1张

概述我有一个UILocalNotification,应该是一天一个星期一到星期五,但不是在周末.我认为将通知的repeatInterval属性设置到NSWeekdayCalendarUnit将会实现这一点.可悲的是,我的通知仍在周末开放.有人可以建议为什么吗这是我的代码: UILocalNotification *localNotification = [[UILocalNotification al 我有一个UIlocalnotification,应该是一天一个星期一到星期五,但不是在周末.我认为将通知的repeatInterval属性设置到NSWeekdayCalendarUnit将会实现这一点.可悲的是,我的通知仍在周末开放.有人可以建议为什么吗这是我的代码:
UIlocalnotification *localnotification = [[UIlocalnotification alloc] init];localnotification.alertAction = @"VIEw";localnotification.alertbody = NSLocalizedString(@"ALERT_MESSAGE",nil);localnotification.soundname = UIlocalnotificationDefaultSoundname;NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"MM-dd-yyyy HH:mm"];[dateFormatter setTimeZone:[NSTimeZone timeZoneWithname:@"America/Toronto"]];// Notification fire times are set by creating a notification whose fire date // is an arbitrary weekday at the correct time,and having it repeat every weekdayNSDate *fireDate = [dateFormatter dateFromString:@"01-04-2012 11:00"]; localnotification.fireDate = fireDate;localnotification.repeatInterval = NSWeekdayCalendarUnit;[[UIApplication sharedApplication] schedulelocalnotification:localnotification];            break;[localnotification release];
解决方法 iOS中的平日就是一星期内的一天.它没有“工作周”的内涵,而不是周末.

文档说明它更清楚一点,建议您使用1-7作为单位:

NSWeekdayCalendarUnit

SpecifIEs the weekday unit.

The corresponding value is an kcfCalendarUnitSecond. Equal to kcfCalendarUnitWeekday. The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday).

资料来源:http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html

要正确设置从星期一到星期五的通知,这里有一些框架代码.你必须执行它5次,所以将其封装在一个fireDate参数的方法中是很好的.我已经展示了如何在星期一做到这一点.

UIlocalnotification *notification = [[[UIlocalnotification alloc] init] autorelease];// Set this to an NSDate that is for the time you want,on Mondaynotification.fireDate = fireDate;            // Repeat every weeknotification.repeatInterval = NSWeekCalendarUnit;
总结

以上是内存溢出为你收集整理的ios – UILocalNotification应该每个工作日重复,但周末也会发生全部内容,希望文章能够帮你解决ios – UILocalNotification应该每个工作日重复,但周末也会发生所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1095631.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存