0
我正試圖在iCal中創建新日曆。現在我可以用某個名稱創建一個新日曆。但我的問題是,當我嘗試創建到本地日曆時,我無法在日曆列表中看到它。任何人對此有任何想法?我嘗試過使用所有類型的數據源,但無法找到確切的解決方案。EKCalender創建日曆,但無法在iCal中看到它
預先感謝您。
我正試圖在iCal中創建新日曆。現在我可以用某個名稱創建一個新日曆。但我的問題是,當我嘗試創建到本地日曆時,我無法在日曆列表中看到它。任何人對此有任何想法?我嘗試過使用所有類型的數據源,但無法找到確切的解決方案。EKCalender創建日曆,但無法在iCal中看到它
預先感謝您。
NSMutableArray *arrAlarm = [[NSMutableArray alloc]init];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:3600];
EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-3600]; //86400 1 day
[arrAlarm addObject:alarm1];
[arrAlarm addObject:alarm2];
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *ekevent = [EKEvent eventWithEventStore:eventStore];
ekevent.title = strname;
NSLog(@"%@",ekevent.startDate);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE MMM d,yyyy"];
NSDate *date = [dateFormatter dateFromString:strdate];
// Convert to new Date Format
[dateFormatter setDateFormat:@"YYYY-MM-DD HH:MM:SS ±HHMM"];
NSString *newDate = [dateFormatter stringFromDate:date];
// dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
// [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"hh:mm a"];
NSDate* firstDate = [dateFormatter dateFromString:time];
NSDate* secondDate = [dateFormatter dateFromString:endtime];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
// Convert to new Date Format
[dateFormatter setDateFormat:@"HH:MM"];
NSString *t11 = [dateFormatter stringFromDate:firstDate];
NSString *t12 = [dateFormatter stringFromDate:secondDate];
NSDate *dt1 = [dateFormatter dateFromString:t11];
NSDate *dt2 = [dateFormatter dateFromString:t12];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh"];
NSString *hourstring = [NSString stringWithFormat:@"%@",
[df stringFromDate:dt1]];
[df setDateFormat:@"mm"];
NSString *minstring = [NSString stringWithFormat:@"%@",
[df stringFromDate:dt1]];
[df release];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
[components setHour: [hourstring intValue]];
[components setMinute: [minstring intValue]];
[components setSecond: 00];
// NSDate *newDate = [gregorian dateFromComponents: components];
[gregorian release];
ekevent.startDate = date;
ekevent.endDate = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date];
[ekevent setCalendar:[eventStore defaultCalendarForNewEvents]];
ekevent.alarms = arrAlarm;
[arrAlarm release];
NSError *err;
[eventStore saveEvent:ekevent span:EKSpanThisEvent error:&err];
試試這個代碼,你會得到想要的結果。
嘿謝謝你的解決方案,但我能夠創建默認類型的日曆事件。我正在嘗試使用ios5的新功能,即我們可以創建特定事件的新日曆。並且可以在iphone的日曆應用程序的日曆列表中查看。我有問題。我可以創建活動以及日曆。但是,當我激活iCloude日曆時,我無法在列表中看到我的日曆。 – user1988