Search code examples
iphoneiosobjective-cipaditunes

Is it possible to block iTunes notifications while a process is running


I'm working on a iOS app where the user is fetching a reasonably sized database online, and then working with it offline. The update, and sync is taking around 10-15 minutes due to the memory constraints on the device and the way I'm handling the transactional inserts. All the while I have a dialog view open notifying the user of the progress, and give him the option of cancelling and reverting the changes to the database.

Anyway, today while testing I noticed that the iTunes app was trying to contact as server and do some background work, but threw an error:

 itunesstored[68] <Warning>: Could not load download manifest with underlying error: 
                             Error Domain=NSURLErrorDomain Code=-1001 "Cannot connect
                             to 112.168.198.2" UserInfo=0x1f8d6150 
                             {NSLocalizedDescription=Cannot connect to 112.168.198.2}

This caused a dialog to display on top of the one I was already displaying, notifying the user that iTunes was unable to connect.

Now when I clicked the 'close' button, that somehow also closed my dialog, causing only parts of the actions, to be taken when the user decides to stop the update, to take place. The async update kept on going in the background, while the database tried to revert the changes causing the database to lock up and I needed to kill the process and restart the app and update. By design, that reverts everything if something terrible like this happens.

Now I noticed that I should make some changes in my code to make it harder for the database to lock up like that, and I'm working on that. But what I want to know is: is it possible to forbid iTunes, or any other process for that matter, to do any work on the UI thread while a certain critical process in your app is taking place?

The behavior of the iTunes dialog cancel button, i.e propagating down into my dialog can't be considered normal or reasonable.


Solution

  • No, this is not possible. Apps should be coded in a way that accounts for these kind of interruptions. For instance, on an iPhone, what happens if a telephone call comes in? It's the apps responsibility to deal with it; the system will let the call come through irrespective of your "critical process".

    In general, it sounds like your app isn't designed in the best way. For instance, 10 minutes to parse a database seems extremely long — how many records does this database have? You should be able to import databases with 100,000 records in a couple of seconds on the iPhone.