Can't show Alertview in EKEventStore

I'm working on a project which involves the iOS EventKit. It needs to be backwards compatible with ios 5. So i've tried implementing a couple of methods found on SO. What happens is, that it crashes when i'm trying to show the UIAlert.

-(void)addToCalender {

    EKEventStore *eventStore = [[EKEventStore alloc] init];

    if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
    {
        __block typeof (self) weakSelf = self; // replace __block with __weak if you are using ARC
        [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
             if (granted)
             {
                 //[weakSelf performSelectorOnMainThread:@selector(addEventToCalendar) withObject:nil waitUntilDone:YES];
                 [weakSelf performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:YES];
             }
             else
             {
                 NSLog(@"Not granted");
                 UIAlertView *alert = [[UIAlertView alloc]
                                       initWithTitle: @"Announcement"
                                       message: @"It turns out that you are playing Addicus!"
                                       delegate: nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];
                 [alert show];
                 [alert release];
             }
         }];
    }
    else
    {
        [self performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];
    }
}

My error message is rather vague, but i guess its something about the mainthreat which cant be fired?

Im not sure. However, i would also like to get the "This App wants your permission" dialog when the permission is not set, is that possible?

Answers


Thanks to Allocating/showing a UIAlertView in a Block statement

dispatch_async(dispatch_get_main_queue(), ^{
  UIAlertView *myAlert = [[[UIAlertView alloc]initWithTitle:@"Calendar Access Denied"
                                                    message:@"Een tekst"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil] autorelease];
  [myAlert show];
});

My assumption was right, it needs to be dispatched at the main thread


I had the same problem. I used the following code. Please use your code here.

dispatch_async(dispatch_get_main_queue(), ^{
    });

For example,

dispatch_async(dispatch_get_main_queue(), ^{
            // alert code
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Your internet connection is currently unavailable. Please try to connect later." delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
            [alert show];
            [alert release];
        });

Need Your Help

uicollectionview scrolling change cell indexpath

ios objective-c uicollectionview nsindexpath

I'm trying to create a week calendar by using uiclloectionview. here is what it would look like when the view come to focus:

HTTP to HTTPS mod_rewrite with clean URLs

apache security mod-rewrite https clean-urls

I am using Apache 2.4.7 on Ubuntu 14.04 LTS. I would like to be able to redirect a URL like this