我的应用程序中有一个按钮,可以调出 EventEditViewControllerWithEventStore 视图。当用户按下完成时,该事件将添加到日历中,并在添加时显示通知。但是,我怎么知道用户是否取消了?到目前为止,无论用户是否按下完成或取消,都会显示通知。
这是我到目前为止所拥有的:
- (IBAction)addEvent:(id)sender {
EKEventStore *eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector: @selector(requestAccessToEntityType:completion:)]) {
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL permissionGranted, NSError *error) {
if (permissionGranted){
NSLog(@"PERMISSION GRANTED.");
[self performSelectorOnMainThread:@selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];
}
else {
NSLog(@"NO PERMISSION.");
[TSMessage showNotificationInViewController:self withTitle:@"Oops! Permission Required" withMessage:@"In order to use this feature, please enable calendar access for this app under settings." withType:TSMessageNotificationTypeWarning withDuration:TSMessageNotificationDurationAutomatic withCallback:nil atPosition:TSMessageNotificationPositionTop];
}
}];
}
else {
// If device is > 6.0
[self presentEventEditViewControllerWithEventStore:eventStore];
}
}
- (void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore
{
EKEventEditViewController *vc = [[EKEventEditViewController alloc] init];
vc.eventStore = eventStore;
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
//Pre-populated Info
event.title = @"Event title";
event.startDate = [NSDate date];
event.endDate = [NSDate date];
event.URL = [NSURL URLWithString:@"http://example.com"];
event.notes = @"Event Notes Can Go Here.";
event.allDay = YES;
event.location = @"Earth";
event.availability = EKEventAvailabilityTentative;
vc.event = event;
vc.editViewDelegate = self;
[self presentViewController:vc animated:YES completion:nil];
}
#pragma EKEventEditViewDelegate
- (void)eventEditViewController:(EKEventEditViewController*)controller
didCompleteWithAction:(EKEventEditViewAction)action {
[controller dismissViewControllerAnimated:YES completion:nil];
[self performSelector:@selector(eventAddedSuccessfully) withObject:nil afterDelay:0.5];
}
#pragma TSMessages
- (void)eventAddedSuccessfully {
NSLog(@"Event was successfully added.");
[TSMessage showNotificationInViewController:self withTitle:@"Success!" withMessage:@"The event was added to your calendar." withType:TSMessageNotificationTypeSuccess withDuration:TSMessageNotificationDurationAutomatic withCallback:nil atPosition:TSMessageNotificationPositionTop];
}