0

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];


}
4

1 に答える 1