2014-02-14 64 views
0

我有一個iCal文件與rRulerRule = "FREQ=WEEKLY;UNTIL=20140425T160000Z;INTERVAL=1;BYDAY=TU,TH";iOS版 - 的iCal RRULE在EKEvent復發規則

我需要把這些信息在EKEvent

EKEvent *event; 
event.recurrenceRules = ... 

我分裂rRule和保存它在NSArray

NSArray * rules = [evento.rRule componentsSeparatedByString:@";"]; 
event.recurrenceRules = rules; 

但是錯誤ocurrs:

-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString relationForKey:]: unrecognized selector sent to instance 0x21283350' 

你能幫幫我嗎? 謝謝你的提前。

回答

4

我發現使用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); 
2

將字符串拆分爲數組時,會得到一個字符串數組。但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 

查看文檔here