Mrunal
Mrunal

Reputation: 14128

dispatch_async crash on iOS device only, why?

My application is crashing at below code point. That to only on device, over simulator application works fine.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
               , ^(void) {

                   // do some time consuming things here
                   // perform task here which required to be run on separate thread/queue

                   CPPClass& ptr = CPPClass::GetInstance();
                   ptr.SyncTrackingData([newObject primaryID]);

                   dispatch_async(dispatch_get_main_queue(), ^{

                       // after completion of those thread tasks
                       // do some things here in the main queue
                       // for example: update UI controls, etc.

                       NSLog(@" Synchronization Done ");
                   });
               });

Here is the app flow for this method execution:

Regarding SyncTrackingData method: This method is available in CPP class file, it is creating new thread over there and using that thread, application data is getting stored to local database file (In document directory).

We are using separate thread for this method - is because as we already have Model objects, view data can be displayed and database filling can be done as background process.

Any guesses what could be the reason.

Upvotes: 0

Views: 830

Answers (1)

Paul Dardeau
Paul Dardeau

Reputation: 2619

Have you looked for any compiler warnings on your code?

If there are no compiler warnings on that code, I would sprinkle some more NSLog statements at different points in the code. Then run the app on your device while the device is connected to your machine that's running Xcode. Watch the console output while the app is running.

Also, you can view the console output after the fact -- when the device is connected, just bring up the Organizer window and click on the "Device Logs" for your device.

Upvotes: 1

Related Questions