With the release of iOS 6.1, my main product at work started flickering pretty badly. Sometimes the whole screen, and sometimes just small regions unrelated to view boundaries. I initially had no idea what was going on, but woke up at 4am the next morning with one thought keeping me awake. UIKit.
A few hours of hunting later and I found it. An UIAlertView was being created and shown from a background thread early in the app setup process, and once you triggered it the flickering continued sporadically until the app was killed with the task switcher. Once you got past this initial setup phase most users never trigger this particular alert view again, so it only affects new users (those most likely to leave App Store reviews). This bugged version is still available in the App Store at the time of this writing because of a software release process that I will rant about another day.
I knew it was almost certainly an alert view triggering this bug, so why hours? Because we have 150+ alert views in this app, and I had to try triggering nearly each and every one of the until I found the right one.
I hate the UIAlertView. How much do I hate it? Let me count the ways.
It’s an ugly hack for lazy programmers to stop the user from interacting with your app on a device that should always be under the users control, 100% of the time. And it can’t even do that. The device has a giant home button that always interrupts program execution and returns the device to the home screen. At any time. Good luck recovering your uninterruptible state upon relaunch when that happens.
It’s too easy to create. You don’t have to stop and think about where it belongs in you’re view hierarchy. You can create and show one anywhere with 2 lines of code and user interaction grinds to a halt. This is where my particular bug came in. My predecessor didn’t stop to think where he was calling it from.
It’s design is crap. Assuming you have a need for such a concept (you don’t), then at least make sure it doesn’t cause a mountain of spaghetti code when used. This class has a single app delegate who’s main method upon return only gives you a button index. It is your responsibility to keep track of what the buttons prompted the user to do, and if you have multiple alerts which one was shown and what the appropriate action to take upon their dismissal should be. This leads to long switch statements dispatching other functions at best, and a giant didDismiss…. function at worst. Let’s face it, you’re always crunched for time and doing the awful hack way.
There is no notification when you screw up. This is more of a UIKit hate in general, but if your going to require all UI state changes happen on the main thread, then by God have some way of enforcing it other than bugging out at runtime. Do some static analysis and throw a compiler warning. Abort() at runtime. Something other than random glitching on users please.
It’s a modal popup. I hate popups. You hate popups. Users hate popups. The only thing worse than a popup is a popup that forces you to interact with it.
It may have been necessary durning the 2.0 days when everything was single threaded, but now UIAlertView is a rotting crutch used by the stupid and the lazy. We’ve got blocks and GCD for doing data crunching in the background while keeping the UI responsive. We’ve got simple synchronization methods for updating the UI when the work is done. Just think about user experience for two seconds before using it. Please. That’s all I ask.
tl/dr; Don’t touch UIKit from background threads. UIAlertView blows.