I have a method which encodes selected songs on iTunes to mp3 using lame. Now I'm calling it from IBAction named "Encode". While encoding, Application fails into not responding state. And when encode is finished, Application come back. I would like to solve this not responding state. Would you teach me how should I approach?
Asked
Active
Viewed 91 times
2 Answers
3
I guess you are doing the encoding on the main thread and this is why your application becomes unresponsive. You may want to read articles about threading and concurrency in order to solve your problem.
There is also an introduction on raywenderlich.com called "Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial".

tilo
- 14,009
- 6
- 68
- 85
-
Thanks for your answer. With your answer, I can find out asynchronous processing which called Operation Queue. – xanadu6291 Feb 28 '14 at 11:11
1
You need to dispatch it on a thread different from the main thread. Otherwise it will block the main thread which is where the GUI part of your app runs.
Here is one example of how to do it. Be careful, though, if you want to modify variables outside the block. You might want to look up the __block keyword.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// INSERT CODE HERE
});

Michael Knudsen
- 629
- 1
- 7
- 23
-
Thank you for the answer. I've found that your answer is GCD. On the other hand, I've found that the way to use Operation Queue, to use NSOperationQueue. I am appreciate if you teach me which is better. – xanadu6291 Feb 28 '14 at 11:07
-
Now I've found the answer for my question, gcd or NSOperation. Here's URL:http://stackoverflow.com/questions/10373331/nsoperation-vs-grand-central-dispatch – xanadu6291 Feb 28 '14 at 12:39
-
I have never looked into NSOperationQueue (it is a rather new thing, I believe), but is definitely on my list. Maybe someone else can assist? – Michael Knudsen Feb 28 '14 at 14:24