使用Objective-C创建iCal(ICS)

时间:2015-03-05 09:47:35

标签: objective-c icalendar

我正在尝试根据this example创建一个合适的ICS文件,但这并不是我想要的。这对我来说是新鲜事,因为我不是iOS开发人员,我需要更多的帮助和方向。

我在应用程序中有一个自定义日历,当我在保存新事件的过程中,我还要添加该事件的ICS文件,然后将其作为参数传递给保存操作。

#pragma mark - ICS
- (NSArray *)mimeWithRecord:(OrderedDictionary *)detailRecord {
NSMutableString *xCalString= [[NSMutableString alloc] init];

[xEvent appendString:[NSString stringWithFormat:@"BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//www.xxx.com//iOS//v1\nMETHOD:PUBLISH\n"]];

NSString *title = self.detailRecordM[@"subject"];
    NSString *inviteesReq = [self inviteeReqStrFromDetailRec:self.detailRecordM];
    NSDate *startdt = [self.df dateFromString:self.detailRecordM[@"starttime"]];
    NSDate *enddt = [self.df dateFromString:self.detailRecordM[@"endtime"]];
    NSDate *dtStamp = [self.df dateFromString:self.detailRecordM[@"dtstamp"]];
    NSString *notesCal = self.detailRecordM[@"bodydata"];
    NSString *locationCal = self.detailRecordM[@"location"];

NSString *uuid = [[NSUUID UUID] UUIDString];
[xEvent appendString:[NSString stringWithFormat:@"BEGIN:VEVENT\nUID:%@\n", uuid]];
    [xCalString appendString:[NSString stringWithFormat:@"DTSTART:%@StartDate\n", startdt]];//Event Start Date
    [xCalString appendString:[NSString stringWithFormat:@"DTEND:%@EndDate\n", enddt]];
    [xCalString appendString:[NSString stringWithFormat:@"DTSTAMP:%@Date\n", dtStamp]];//date the event was created
    [xCalString appendString:[NSString stringWithFormat:@"LAST-MODIFIED:%@\n", startdt]];//date the event was modified
    [xCalString appendString:[NSString stringWithFormat:@"ATTENDEE:%@\n", inviteesReq]];//Invitees
    [xCalString appendString:[NSString stringWithFormat:@"LOCATION:%@\n", locationCal]];//location
    [xCalString appendString:[NSString stringWithFormat:@"SEQUENCE:0"]];//When a calendar component is created, its sequence number is zero
//status
if ([_detailRecordM[@"meetingstatus"] isEqualToString:@"1"]) {
    [xCalString appendString:@"\r\nSTATUS:CONFIRMED"];
}
if ([_detailRecordM[@"meetingstatus"] isEqualToString:@"2"]) {
    [xCalString appendString:@"\r\nSTATUS:TENTATIVE"];
}
if ([_detailRecordM[@"meetingstatus"] isEqualToString:@"3"]){
    [xCalString appendString:@"\r\nSTATUS:CANCELLED"];
}
    [xCalString appendString:[NSString stringWithFormat:@"SUMMARY:%@\n", title]];//Event Title
    [xCalString appendString:[NSString stringWithFormat:@"DESCRIPTION:%@\n", notesCal]];//Notes
[xCalString appendString:@"\r\nEND:VEVENT"];

 //The last line must be "END:VCALENDAR"
[xCalString appendString:@"END:VCALENDAR"];

NSData *ret = [xEvent dataUsingEncoding:NSUTF8StringEncoding];

return nil; 
}

#pragma mark - Actions
-(IBAction)doneAction:(id)sender {
//save the event and send event refresh event from CAPI

    //TODO: create ICS event and insert into a MIME
    NSArray *mimeMessages = [self mimeWithRecord:self.detailRecordM];     
}

0 个答案:

没有答案