[英]iOS - iCal rRule in a EKEvent recurrence rule
我有一個帶rRule
的iCal
文件: rRule = "FREQ=WEEKLY;UNTIL=20140425T160000Z;INTERVAL=1;BYDAY=TU,TH";
我需要將此信息放在EKEvent
:
EKEvent *event;
event.recurrenceRules = ...
我拆分了rRule
並將其保存在NSArray
:
NSArray * rules = [evento.rRule componentsSeparatedByString:@";"];
event.recurrenceRules = rules;
但是會發生錯誤:
-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350'
你能幫助我嗎? 謝謝您的提前。
我使用EKRecurrenceRule + RRULE庫找到了解決方案,它非常易於使用。
鏈接: https : //github.com/jochenschoellig/RRULE-to-EKRecurrenceRule
使用示例:
NSString *rfc2445String = @"FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2"; // The 2nd to last weekday of the month
// Result
EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initWithString:rfc2445String];
NSLog(@"%@", recurrenceRule);
將字符串拆分為數組時,將得到一個字符串數組。 但是recurrenceRules
屬性需要一個EKRecurrenceRule
對象數組。 您必須自己解析字符串並將其轉換為EKRecurrenceRule
對象。 復雜的重復規則應使用以下方法:
- (id)initRecurrenceWithFrequency:(EKRecurrenceFrequency)type interval:(NSInteger)interval daysOfTheWeek:(NSArray *)days daysOfTheMonth:(NSArray *)monthDays monthsOfTheYear:(NSArray *)months weeksOfTheYear:(NSArray *)weeksOfTheYear daysOfTheYear:(NSArray *)daysOfTheYear setPositions:(NSArray *)setPositions end:(EKRecurrenceEnd *)end
在這里查看文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.