1
NSDictionary *d = (NSDictionary *) [arrGarden objectAtIndex:0];
int intarrCount=0;
NSString *strDate =[NSString stringWithFormat:@"%@", [d valueForKey:@"open_date_for_calendar"]];
NSArray *arrDateList =[strDate componentsSeparatedByString:@","];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
for(int i=0;i<[arrDateList count];i++)
{
intarrCount++;
EKEventStore *eventDB = [[EKEventStore alloc] init];
EKEvent *myEvent = [EKEvent eventWithEventStore:eventDB];
NSString *trimmedString = [[arrDateList objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// NSString *trimmedString = [NSString stringWithFormat:@"%@",[[arrDateList objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
myEvent.title = [d valueForKey:@"garden_name"];
myEvent.startDate = [dateFormatter dateFromString:trimmedString];
//myEvent.endDate = [dateFormatter dateFromString:trimmedString];
myEvent.endDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:myEvent.startDate];
myEvent.allDay = YES;
[myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];
NSError *err;
[eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err];
//NSString *eID = myEvent.eventIdentifier;
if(intarrCount == [arrDateList count])
{
if (err == noErr) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Event Added to your calendar"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
上述我行的,我用代碼..如何使用EKEvent?
當我添加事件到日曆事件成功添加日曆,但10-15秒後,事件被自動刪除... 請幫我在哪裏我有錯誤的代碼行 謝謝....
請檢查您的結束日期。你添加時間間隔0.所以也許它刪除了。 – 2012-08-01 08:37:23
我也改變它,但不能工作... – user1324145 2012-08-01 08:39:12