EKEvent保存在iPad日历中但不保存在iPhone日历中

时间:2013-04-30 07:48:54

标签: objective-c xcode icalendar ekevent

在我的应用中,我需要将事件保存到设备日历中。目前,它确实保存在iPad日历中,但不会保存在iPhone日历中,这很奇怪。

这是我的代码:

-(IBAction)addToCalendar:(id)sender
{
     EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];

    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    event.title     = titleString;

    NSString *dateString = eventStartDate;
    NSString *endString = eventEndDate;

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"MM/dd/yyyy"];
    NSDate *dateFromString = [dateFormatter dateFromString:dateString];
    NSDate *dateToString = [dateFormatter dateFromString:endString];
    // voila!
    //        dateFromString = [dateFormatter dateFromString:dateString];
    //        dateToString = [dateFormatter dateFromString:endString];

    //(@"date %@  %@", dateFromString, dateToString);
    event.startDate = dateFromString;
    event.endDate = dateToString;

    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *err;

   BOOL saved =  [eventStore saveEvent:event span:EKSpanThisEvent error:&err];

    //(@"err %@", err);
    if (saved) {

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"BHCS" message:@"Event saved to calendar." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }

}

如何解决此问题?

0 个答案:

没有答案