0

My application stuck with CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION. In my application, I called an C function which is async. I show an waiting msg during the execution.
When this function is terminated, it calls a delegate to close that waiting msg and show in same time an AlertView.

I use gcd to show the alertview

dispatch_async(dispatch_queue_create("com.myapp.service.waitingmessage", nil), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *anAlert = ...
            [anAlert show];
             });
        });

Here is the screenshot of the Debugger XCode when application got stuck. I see also that the CPU usage of my application is up to 100%, maybe that why the application is suspended by the system.

enter image description here

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
Duyen-Hoa
  • 15,384
  • 5
  • 35
  • 44
  • I'm not following exactly what you're trying to run in the background. You're creating a background queue and immediately stuffing it with a main loop block. You could delete the first and last line and obtain the same effect. Also note that `UIAlertView` is deprecated and you'll get any kind of block-wise handling y using a `UIAlertController`. – iluvcapra Nov 04 '14 at 19:38
  • I've fixed the problem. This is caused by another block of code. PS: The UIAlertView is only obsoleted from iOS 8.0 – Duyen-Hoa Nov 05 '14 at 09:16

1 Answers1

-1

Use dispatch_sync() in place of dispatch_async(dispatch_get_main_queue(), ^{...

You can't update the UI from a background thread.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
  • 1
    But in my dispatch_async, I add the code to be executed in the main queue. I think that it's correct to update the UI like that. – Duyen-Hoa Oct 22 '14 at 12:19
  • 1
    You should't execute too your async on main queue. The best practice is to create a background queue to use it with dispatch_async() and use dispatch_get_main_queue() for your dispatch_sync() calls. – David Ansermot Oct 22 '14 at 12:26