简体   繁体   中英

iOS EKEventEditViewController how do I force the Alert to “At time of event”?

A 2 part question: Using the SDK's view controller to add an event is working, but I would like to have it default to Alert = "At time of event" or any other of the available options; how do I do that?. Secondly, I would like to have an alert display when the event is finished . I tried adding an EKAlarm set to endDate, but no alert is fired. Can this be done when using the SDK's EKEventEditViewController?

If what I'm trying to falls in the category of customizing the EKEventEditViewController, then I think most other Qs on SO say that it is not allowed example .

Here is the code (iOS 7):

- (void)eventEditViewController:(EKEventEditViewController *)controller
      didCompleteWithAction:(EKEventEditViewAction)action{
AlarmTimerTriggersTVC * __weak weakSelf = self;
// Dismiss the modal view controller
[self dismissViewControllerAnimated:YES completion:^
 {
     if (action != EKEventEditViewActionCanceled)
     {
         dispatch_async(dispatch_get_main_queue(), ^{

             EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:controller.event.endDate];
             controller.event.alarms = [NSArray arrayWithObject:alarm];

             // Re-fetch all events happening in the next 24 hours
             weakSelf.eventsList = [self fetchEvents];
             // Update the UI with the above events
             [weakSelf.tableView reloadData];
             });
         }
     }];
}

Try to save the event after setting the alarm on it

EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:controller.event.endDate];
controller.event.alarms = [NSArray arrayWithObject:alarm];

NSError* error = nil;

[eventStore saveEvent: controller.event
                 span: span
                error: &error]; 

EDIT:

For the time of the event its something like this

controller.event.alarms = [NSArray arrayWithObject:
                           [EKAlarm alarmWithRelativeOffset: 0]];

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