关于异步:iOS 在长时间运行任务后显示警报视图 | 珊瑚贝

iOS show alert view after long running task


我真的被我遇到的这个问题难住了。

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

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

我试过:

1
[self showAlertView];

但这会使应用程序崩溃,因为我不再在该视图中。

比我试过的:

1
2
3
4
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 节拍,当用户进入时让它工作会容易得多应用程序也是如此,那么我不必担心所有这些)。

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

  • dispatch_async() 应该可以工作。您确定程序执行正在到达该块(即,如果您在此处设置断点,它会停止吗)?


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

只需将其添加到应用委托类:

1
2
3
4
5
– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:notification.alertBody message:nil delegate:nil cancelButtonTitle:@”Oke” otherButtonTitles:nil];
    [alert show];

}

  • 效果很好,感谢您的快速回复。我看到你在 iOS 力量中很强大(因此有 30k 代表)=D。你只是让我的应用程序好一百万倍。再次感谢


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

1
2
3
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *controller = window.rootViewController;
// Use controller to display your window.

来源:https://www.codenong.com/18382493/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9033.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?