所以根据这个规则,事件应该每年添加一次,每年的6月1日和7月,直到到期日,我已经在我的项目中设置了.
在我的项目中,会创建事件,但不会根据重复规则创建事件.使用以下代码,事件仅在6月1日星期四添加.为什么每个7月1日星期四都没有添加活动呢?
这是.m文件代码
- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; // Do any additional setup after loading the vIEw,typically from a nib. [self createEvent];}- (voID)createEvent{ EKEventStore *eventStore = [[EKEventStore alloc] init]; EKEvent *event = [EKEvent eventWithEventStore:eventStore]; event.Title = @"testRecurrenceRule"; event.location = @"Dhaka"; [event setCalendar:[eventStore defaultCalendarForNewEvents]]; event.startDate = [self dateFromString:@"2013-06-18T21:00:00+06:00"]; event.endDate = [self dateFromString:@"2013-06-18T22:00:00+06:00"]; ID recurrenceRule = [self recurrenceRuleForEvent]; if(recurrenceRule != nil) [event addRecurrenceRule:recurrenceRule]; if ([eventStore respondsToSelector:@selector(requestAccesstoEntityType:completion:)]) { // iOS 6 and later [eventStore requestAccesstoEntityType:EKEntityTypeEvent completion:^(BOol granted,NSError *error) { if (granted) { dispatch_async(dispatch_get_main_queue(),^{ [self saveTheEvent:event eventStore:eventStore]; //[eventStore saveEvent:event span:EKSpanThisEvent error:error]; }); } else { dispatch_async(dispatch_get_main_queue(),^{ //do nothing }); } }]; } else { [self saveTheEvent:event eventStore:eventStore]; } textVIEw.text = [Nsstring stringWithFormat:@"Event has been added with recurrence rule %@",recurrenceRule];}- (voID)saveTheEvent:(EKEvent *)aEvent eventStore:(EKEventStore *)aStore{ [aStore saveEvent:aEvent span:EKSpanThisEvent error:NulL];}- (EKRecurrenceRule *)recurrenceRuleForEvent{ //just creating a recurrence rule for RRulE:FREQ=YEARLY;BYMONTH=6,7;BYDAY=1TH // setting the values directly for testing purpose. //FREQ=YEARLY EKRecurrenceFrequency recurrenceFrequency = EKRecurrenceFrequencyYearly; NSInteger recurrenceInterval = 1; EKRecurrenceEnd *endRecurrence = nil; NSMutableArray *monthsOfTheyeararray = [NSMutableArray array]; NSMutableArray *daysOfTheWeekArray = [NSMutableArray array]; NSMutableArray *daysOfTheMonthArray = [NSMutableArray array]; NSMutableArray *weeksOfTheyeararray = [NSMutableArray array]; NSMutableArray *daysOfTheyeararray = [NSMutableArray array]; NSMutableArray *setpositionsArray = [NSMutableArray array]; //BYMONTH=6,7 [monthsOfTheyeararray addobject:[NSNumber numberWithInt:6]]; [monthsOfTheyeararray addobject:[NSNumber numberWithInt:7]]; //BYDAY=1TH [daysOfTheWeekArray addobject:[EKRecurrenceDayOfWeek dayOfWeek:5 weekNumber:1]]; endRecurrence = [EKRecurrenceEnd recurrenceEnDWithEndDate:[self dateFromString:@"2018-12-15T22:30+06:00"]]; EKRecurrenceRule *recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:recurrenceFrequency interval:recurrenceInterval daysOfTheWeek:daysOfTheWeekArray daysOfTheMonth:daysOfTheMonthArray monthsOfTheyear:monthsOfTheyeararray weeksOfTheyear:weeksOfTheyeararray daysOfTheyear:daysOfTheyeararray setpositions:setpositionsArray end:endRecurrence]; return recurrence;}- (NSDate *)dateFromString:(Nsstring *)string{ //check if the date string in null if ([string length] == 0) return nil; Nsstring *dateString = nil; Nsstring *modifIEdString = nil; BOol secSpotMissing = false; NSRange range = [string rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"T"]]; if (range.location != NSNotFound) { dateString = [string substringFromIndex:range.location]; range = [dateString rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"+-Z"]]; if (range.location != NSNotFound) { //seperate the time portion of date string and checking second fIEld is missing or not. like is it HH:mm or HH:mm:ss? if ([[[dateString substringToIndex:range.location] componentsSeparatedByString:@":"] count] < 3) secSpotMissing = true; //seperate the time zone portion and checking is there any extra ':' on it. It should like -0600 not -06:00. If it has that extra ':',just replacing it here. dateString = [dateString substringFromIndex:range.location]; if([dateString hasSuffix:@"Z"]) modifIEdString = [dateString stringByReplacingOccurrencesOfString:@"Z" withString:@"+0000"]; else modifIEdString = [dateString stringByReplacingOccurrencesOfString:@":" withString:@""]; string = [string stringByReplacingOccurrencesOfString:dateString withString:modifIEdString]; } } else return nil; // converting the date string according to it's format. NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; if (secSpotMissing) [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mmZZZ"]; else [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"]; return [dateFormatter dateFromString:string];}
有人可以帮我解决这个问题吗?
解决方法 这似乎是另一个问题的重复.基本上,根据“BYDAY”规则,YEARLY频率的第1周意味着一年中的第一周 – 而不是每个月的第一周.@Shuvo,我没看过rfc.但这里是Apple文档EKRecurrenceDayOfWeek.
The EKRecurrenceDayOfWeek class represents a day of the week for use with an EKRecurrenceRule object. A day of the week can optionally have a week number,indicating a specific day in the recurrence rule’s frequency. For example,a day of the week with a day value of Tuesday and a week number of 2 would represent the second Tuesday of every month in a monthly recurrence rule,and the second Tuesday of every year in a yearly recurrence rule.
当你说“第一个星期四”时,这是正确的 – 除了在每年的背景下,它是一年的第一个星期四.
@H_403_2@ 总结以上是内存溢出为你收集整理的ios – 根据给定的EKRecurrenceRule不添加EKEvent全部内容,希望文章能够帮你解决ios – 根据给定的EKRecurrenceRule不添加EKEvent所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)