-
-
Save seanicus/dba273d4d3093765f77d64bd372d3e6a to your computer and use it in GitHub Desktop.
ViewController sample code for EventKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// eventFiddler | |
// | |
// Created by Sean Roberts on 5/17/17. | |
// Copyright © 2017 Red Shed Technology. All rights reserved. | |
// | |
#import "ViewController.h" | |
@import EventKit; | |
@interface ViewController () | |
@property (strong, nonatomic) EKEventStore *eventStore; | |
// Indicates whether app has access to event store. | |
@property (nonatomic) BOOL isAccessToEventStoreGranted; | |
// The data source for the table view | |
@property (strong, nonatomic) NSMutableArray *todoItems; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[self updateAuthorizationStatusToAccessEventStore]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (EKEventStore *)eventStore { | |
if (!_eventStore) { | |
_eventStore = [[EKEventStore alloc] init]; | |
} | |
return _eventStore; | |
} | |
- (void)updateAuthorizationStatusToAccessEventStore { | |
// 2 | |
EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]; | |
switch (authorizationStatus) { | |
// 3 | |
case EKAuthorizationStatusDenied: | |
case EKAuthorizationStatusRestricted: { | |
self.isAccessToEventStoreGranted = NO; | |
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Access Denied" | |
message:@"This app doesn't have access to your Reminders." delegate:nil | |
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; | |
[alertView show]; | |
break; | |
} | |
// 4 | |
case EKAuthorizationStatusAuthorized: | |
self.isAccessToEventStoreGranted = YES; | |
break; | |
// 5 | |
case EKAuthorizationStatusNotDetermined: { | |
__weak ViewController *weakSelf = self; | |
[self.eventStore requestAccessToEntityType:EKEntityTypeReminder | |
completion:^(BOOL granted, NSError *error) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
weakSelf.isAccessToEventStoreGranted = granted; | |
//[weakSelf.tableView reloadData]; | |
}); | |
}]; | |
break; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment