iOS长时间运行任务后显示警报视图

时间:2013-08-22 13:54:22

标签: ios asynchronous uialertview

我对这个问题感到非常难过。

所以我们有一个应用程序,允许用户将一些照片同步到我们的服务器。所以我通过dispath_async调用完成了它并且它可以工作,但是我想告诉用户它已经完成了天气成功。

所以我的问题是如何向用户显示一个AlertDialog框,当我不知道它们将在哪个视图时(因为它是异步的我不希望它们必须留在那个ViewController上,而是移动到应用程序并在上传时执行其他操作。)

我试过了:

[self showAlertView];
但这会导致应用程序崩溃,因为我不再使用该视图了。

比我尝试过:

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
});

哦和LocalNotifications不会起作用,因为如果他们在应用程序中它没有显示(Android在这方面有iOS打败,那么当用户进入时,只需要工作就会容易得多也是应用程序,然后我不必担心所有这些。)

关于如何实现目标的任何想法。

2 个答案:

答案 0 :(得分:4)

即使应用程序在前台运行,您也可以使用UILocalNotification,但您必须自行处理通知。您只需显示一个简单的AlertView。

只需将其添加到app delegate类:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:notification.alertBody message:nil delegate:nil cancelButtonTitle:@"Oke" otherButtonTitles:nil];
    [alert show];

}

答案 1 :(得分:0)

您可以通过应用程序窗口访问控制器,在当前控制器上显示模态视图。

UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *controller = window.rootViewController;
// Use controller to display your window.
相关问题