Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions EventTest/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ @interface ViewController ()

@end

@implementation ViewController
@implementation ViewController {
EKEventStore* eventStore;
}

- (void)viewDidLoad {
[super viewDidLoad];

static EKEventStore* eventStore;
if (!eventStore) {
eventStore = [[EKEventStore alloc] init];
eventStore = [EKEventStore new];
}

NSArray* cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
NSLog(@"1st time calendars @%", cals);
// Tu wywaliłem
// NSArray* cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
// NSLog(@"1st time calendars %@", cals);

EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];

Expand All @@ -25,36 +27,26 @@ - (void)viewDidLoad {
case EKAuthorizationStatusAuthorized:
{
NSLog(@"permission was already granted before");
NSArray* cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
// NSArray *cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
[self pullEvents];
break;
}
case EKAuthorizationStatusNotDetermined:
{
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSLog(@"granted after user confirmation");
dispatch_sync(dispatch_get_main_queue(), ^{
[eventStore reset];
// refetch calendars
NSArray* cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];
NSLog(@"calendars @%", cals);
});
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning" message:@"Permission was not granted for Calendar"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
__weak typeof(self) weakSelf = self;
[eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError *error) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[weakSelf calendarAccessGranted:granted];
}];
}];
}
break;
case EKAuthorizationStatusDenied:
case EKAuthorizationStatusRestricted:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning" message:@"Permission was not granted for Calendar"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning"
message:@"Permission was not granted for Calendar"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
Expand All @@ -66,6 +58,35 @@ - (void)viewDidLoad {
}
}

- (void)calendarAccessGranted:(BOOL)granted {
if (granted) {
[self pullEvents];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning"
message:@"Permission was not granted for Calendar"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}

}

// Na moim symulatorze działa i zwraca kalendarze
// Mam nadzieję że pomoże
- (void)pullEvents {
// NSLog(@"granted after user confirmation");

NSArray* cals = [eventStore calendarsForEntityType:EKEntityTypeEvent];

// dispatch_sync(dispatch_get_main_queue(), ^{
// [eventStore reset];
// // refetch calendars
//
// NSLog(@"calendars %@", cals);
// });
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
Expand Down