UIButton から応答するように設定された次のコードを使用して、iPhone アプリからネイティブ iOS カレンダー イベント編集ウィンドウをモーダルに呼び出そうとしています。
- (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 では動作しない理由を知っている人はいますか??
ありがとう