I’m trying to display a UIAlertView after some time (like 5 minutes after doing something in the app). I’m already notifying the user if the app is closed or in background. But I want to display a UIAlertView while the app is running.
I tried to dispatch_async as follows but the alert is popping forever:
[NSThread sleepForTimeInterval:minutes];
dispatch_async(dispatch_get_main_queue(),
^{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title!" message:@"message!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
);
Also, I read that the thread dies after 30 to 60 minutes. I want to be able to display the alert after more than 60 min.
Why not use an
NSTimer, why would you need to use GCD in this case?Then, within the same class, you’d have something like this:
Also, as @PeyloW noted, you can use
performSelector:withObject:afterDelay:too:EDIT You can now also use GCD’s
dispatch_afterAPI: