我正在尝试使用以下代码集从我的 iPhone 应用程序模态调用本机 iOS 日历事件编辑窗口以从 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];
}
此代码在同一应用程序的 iPad 版本中运行良好,但会导致 iPhone 崩溃并显示消息"[EKEventEditor actionSheetShowing]: unrecognized selector sent to instance <0xXXXXXXX>"
任何人都知道为什么这段代码应该在 iPad 上正常工作但在 iPhone 上不能正常工作?
谢谢