2

我的 EKEvent 没有保存在我的 iphone 5 ios 6.1 中,但它保存在我的 ipod 6.0 中。当我更新我的事件并保存它时,该事件被删除。请帮我修复它。它是一个ios错误吗?或者只是在代码中?

这是我的代码:

- (IBAction)submitButtonPressed:(id)sender {
    if (!self.eventStore) {
        self.eventStore = [[[EKEventStore alloc]init]autorelease];
    }

    if (!self.event) {
        self.event  = [EKEvent eventWithEventStore:self.eventStore];
    }

    if ([self.eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
    {
        // the selector is available, so we must be on iOS 6 or newer
        [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (error)
                {
                    NSLog(@"error: %@",error);
                    // display error message here
                }
                else if (!granted)
                {
                    NSLog(@"error: Access Denied");
                    // display access denied error message here
                }
                else
                {
                    // access granted
                    if (!self.isEditing) {
                        [self.event setCalendar:[self.eventStore defaultCalendarForNewEvents]];
                    }
                    [self sendEvent];

                }
            });
        }];
    }
    else
    {
        [self.event setCalendar:[self.eventStore defaultCalendarForNewEvents]];
        [self sendEvent];
    }
}

-(void)sendEvent {
    self.event.title = self.eventModel.eventName;
    self.event.location = self.eventModel.eventLocation;
    self.event.notes = self.eventModel.eventDescription;
    self.eventModel.date = self.datePicked;
    NSString *fromTime = [NSString string];
    NSString *toTime = [NSString string];
    if (self.eventModel.fromTime) {
        fromTime = [NSString stringWithFormat:@"%@:%@",[ self.eventModel.fromTime objectForKey:@"hour"],[self.eventModel.fromTime objectForKey:@"minute"]];
    }

    if (self.eventModel.toTime) {
        toTime = [NSString stringWithFormat:@"%@:%@",[ self.eventModel.toTime objectForKey:@"hour"],[self.eventModel.toTime objectForKey:@"minute"]];
    }

    //set start date and time
    NSDateFormatter *tempFormatter = [[[NSDateFormatter alloc]init] autorelease];
    [tempFormatter setDateFormat:@"yyyy-MM-dd hh:mm"];
    NSString *dateandtime =[NSString stringWithFormat:@"%@%@%@",self.eventModel.fromDate,@" ", fromTime];

    //set end date and time
    NSDateFormatter *tempFormatterTo = [[[NSDateFormatter alloc]init] autorelease];
    [tempFormatterTo setDateFormat:@"yyyy-MM-dd hh:mm"];
    NSString *dateandtimeTo =[NSString stringWithFormat:@"%@%@%@",self.eventModel.toDate,@" ", toTime];

    self.event.startDate = [tempFormatter dateFromString:dateandtime];
    self.event.endDate = [tempFormatterTo dateFromString:dateandtimeTo];
    self.event.allDay = self.eventModel.allDay;

    [self.eventStore saveEvent:self.event span:EKSpanFutureEvents error:&err];

}
4

0 回答 0