I'm pretty new to blocks in objective C. I've read the docs and I have a pretty basic understanding of them.
Why won't this work? This is a framework callback for requesting Calendar access. It takes a block as an argument. All I want to do is allocate and show the UIAlertView in the block, but it will crash when it tries to show.
I hope this isn't a silly question... all the intro examples on the net using blocks just show trivial examples with counters.
//Request access
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted == FALSE) {
UIAlertView *myAlert = [[[UIAlertView alloc]initWithTitle:@"Calendar Access Denied"
message:@"<InfoText>"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[myAlert show];
}
else {
[self addToCalendar];
}
}];
have you tried?
if (granted == FALSE)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *myAlert = [[[UIAlertView alloc]initWithTitle:@"Calendar Access Denied"
message:@ <InfoText>"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[myAlert show];
});
}
this makes calls back in the main thread, useful for mixing blocks and UIKit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With