简体   繁体   中英

EKEventEditor crash on iPhone but not on iPad

I'm trying to call a native iOS calendar event edit window modally from my iPhone app using the following code set to respond from a UIButton:

- (void) initCalendar:(id) sender {

EKEventStore *eventStore = [[EKEventStore alloc] init];

if([eventStore respondsToSelector:
    @selector(requestAccessToEntityType:completion:)]) {

    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

        [self performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];
    }];

} else {

    [self presentEventEditViewControllerWithEventStore:eventStore];

}

}

- (void) presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore {

EKEvent *event = [EKEvent eventWithEventStore:eventStore];

event.title = _meeting.meeting_title;

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: _meeting.date];

NSString *meetingTimeString = _meeting.time;

NSRange lastColonInTimeString = [meetingTimeString rangeOfString:@":" options:NSBackwardsSearch];
NSString *timeHour = [meetingTimeString substringToIndex:lastColonInTimeString.location];
NSString *timeMinute = [meetingTimeString substringFromIndex:lastColonInTimeString.location];

[components setHour:[timeHour integerValue]];
[components setMinute: [timeMinute integerValue]];
[components setSecond: 00];

NSDate *fullDateAndTime = [gregorian dateFromComponents: components];

event.startDate = fullDateAndTime;
event.allDay = NO;
event.endDate = [[NSDate alloc] initWithTimeInterval:7200 sinceDate:fullDateAndTime];
event.notes = [NSString stringWithFormat:@"%@ %@", _meeting.user_notes, _meeting.organizer_notes];
event.location = [NSString stringWithFormat:@"%@, %@",_meeting.location_long, _meeting.location_lat];

[event setCalendar:[eventStore defaultCalendarForNewEvents]];

EKEventEditViewController* controller = [[EKEventEditViewController alloc] init];
controller.eventStore = eventStore;
controller.event = event;
controller.editViewDelegate = self;

[self presentViewController:controller animated:YES completion:nil];

}

This code is working fine within an iPad version of the same app, but causes a crash on iPhone with message "[EKEventEditor actionSheetShowing]: unrecognized selector sent to instance <0xXXXXXXX>"

Anyone got any ideas why this code should work fine on iPad but not on iPhone??

Thanks

I am using iOS 6.x. My testing code is okay on iPhone.

EKEventEditViewController* controller = [[EKEventEditViewController alloc] init];
controller.allowsEditing = YES;
controller.event = event;
[self presentViewController:controller animated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM