我要去假設應用程序是針對iOS 6的
記住應用程序必須「問」的用戶,如果應用程序可以訪問該日曆。
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
[self performSelectorOnMainThread:@selector(showCalendarEventViewControllerWithEventStore:) withObject:eventStore waitUntilDone:YES];
}] ;
-(void) showCalendarEventViewControllerWithEventStore: (EKEventStore *) eventStore
{
EKEventEditViewController * vc = [[EKEventEditViewController alloc] init];
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
event.title = [NSString stringWithFormat:@"Take %@" , self.prescription.lastFilledLabelName];
event.startDate = [[NSDate date] dateByRoundingToNextMinute:15];
event.endDate = [event.startDate dateByAddingTimeInterval:15*60];
event.notes = self.prescription.directions;
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-15*60] ;
event.alarms = [NSArray arrayWithObject:alarm];
vc.eventStore = eventStore;
vc.event = event;
vc.editViewDelegate = self;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:vc animated:YES completion:nil];
}
用戶運行應用程序一次後,該應用程序將顯示在隱私設置中。