Hello everyone I'm adding a simple feature in my xcode ios app that has a UISwitch. When the UISwitch is on an event is created (this part works fine). But when I turn the UISwitch off I cannot find a way to remove the event. If I use code in the second if statement to remove the event, the event identifier is undeclared because it is in a separate if statement. Can someone please tell me what code I need to remove the event.
Code:
- (IBAction)switchon:(id)sender {
if (switchoutlet.on) {
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Event A";
event.startDate = [NSDate dateWithTimeIntervalSince1970:1406948400]; //today
event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
NSString *savedEventId = event.eventIdentifier; //this is so you can access this event later
}];
}
if (!switchoutlet.on) {
//remove event
}
}