Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get immediate value from UIALertView

Tags:

ios

iphone

ipad

I have what can be most accurately described as a Factory, which is generating some NSOperations. Before the NSOPerations are generated, I would like to check the current network status and, if the user is on a 3G/Mobile connection, warn them that they are about to do a data-heavy operation.

I attempted to do this with a UIAlertView, but the only way I can see to get the "response" from a UIAlertView is via the event-based delegate system. I was wondering if there was any way to have it act like the "confirm" dialogue in JavaScript, where it blocks the UI and I can get an immediate value from it once it is dismissed.

Is there any standard way to do this, or some example code I could be pointed towards that accomplishes something similar?

like image 239
Mike Trpcic Avatar asked Nov 04 '22 12:11

Mike Trpcic


1 Answers

Blocking the main thread is considered bad practice on iOS, and thus there is no synchronous API for UIAlertView.

You should implement a delegate callback for the alert that enqueues the relevant NSOperation. It may be useful to subclass UIAlertView to store the relevant data you need to enqueue the NSOperation, or better yet store a block that captures the relevant variables and then just execute that when the user confirms the dialog.

like image 196
Andrew Pouliot Avatar answered Nov 15 '22 01:11

Andrew Pouliot