Reputation: 3629
I am really stumped on this one issue I am having.
So we have an app that allows the user to sync some photos to our server. So I accomplished that with a dispath_async call and it works, however I would like to tell the user that it has finished weather successful or not.
So my question is how do I show the user an AlertDialog box, when I DO NOT know what view they will be on(since it's async I don't want them to have to stay on that ViewController, but move around the app and do other things while that is being uploaded).
I have tried:
[self showAlertView];but that crashes the app because I am no longer on that view.
Than I tried:
dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView* alert = [UIAlertView withTitle ....]; // you get the idea, just create a simple AlertView [alert show]; // also tried: [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; here and that didn't work either });
Oh and LocalNotifications aren't going to work because if they are in the app it doesn't show up(Android has iOS beat on this front, it would be a lot easier to have that just work when the user is in the app too, then I wouldn't have to worry about all of this).
Any ideas on how I can accomplish my goal.
Upvotes: 0
Views: 1040
Reputation: 70185
You can display a modal view on the current controller by accessing the controller through your application's window.
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *controller = window.rootViewController;
// Use controller to display your window.
Upvotes: 0
Reputation: 69479
You can use UILocalNotification
even if the app is running in the foreground but you will have to handle the notification your self. You can just display an simple AlertView.
Just add this to the app delegate class:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:notification.alertBody message:nil delegate:nil cancelButtonTitle:@"Oke" otherButtonTitles:nil];
[alert show];
}
Upvotes: 4