Application Specific Information:
com.my-app failed to launch in time
Elapsed total CPU time (seconds): 20.090 (user 20.090, system 0.000), 100% CPU
Elapsed application CPU time (seconds): 17.598, 87% CPU
I’ve made a modification to my app and as a result I now run a function from applicationDidFinishLaunching which will do some database processing.
I’m basically creating some new records and updating some existing ones.
For one of my existing beta testers / real customers, this is taking 20 seconds to complete.
Although in this case this is a one off, users could experience this situation if they haven’t used the app for a while.
Normally the process wouldn’t take long at all, as there would only be a few transactions to process.
I’m unsure how to proceed, any suggestions ?
I suggest you to do your db processing in the background. Maybe you could disable the interface or display a waiting indicator while you are updating the db in the background thread. Then, once finished you could enable the interface or hide the indicator.
There are different ways to create background thread.
NSThreadclassNSOperationandNSOperationQueueclassesHope it helps.
Edit
Here simple code for your goal (following @JeremyP suggestion).
First, create a
NSOperationsubclassThen, in your application delegate for example call
[self import];that could be defined as follow: