3

At the very beginning of my app, I try to load every UIDocument to get a little preview of their contents. This works very well most of the time, but sometimes I get a crash right after loading a UIDocument. My problem is that I have no idea how to interpret the crash. I don't even know for sure if it is related to the handling of a UIDocument (Thread 6 and 7 were concerned with UIDoc, but Thread 8 seems to have caused the crash).

If somebody could help me to interpret this, I'd be very grateful:

enter image description here

I have breakpoints on on all exceptions, but the debugger won't stop at a specific line of code.

n.evermind
  • 11,944
  • 19
  • 78
  • 122
  • what's the error in the console, and can you verify that you successfully opened your `UIDocument`? (lots of operations are async) – danqing Aug 06 '12 at 06:51
  • 1
    @iBlue there is no output in the console at all. The UIDoc was not successfully opened, i.e. what ever I have in the success block of openWithCompletionHandler:^(BOOL success) is not executed. It crashes before. So I guess the crash screenshot I've provided does not really say much about the error source, does it? – n.evermind Aug 06 '12 at 07:34
  • 1
    @n.evermind, me too having the similar issue...can you show us how you fixed it? It would be very helpful for me. – Ananth Jan 22 '13 at 14:04

1 Answers1

0

I had the same problem. It was easy to reproduce on only one of our testing devices, reading an iCloud document. Reinstalling the app did not affect the bug.

I was using a NSMetadataQuery to get the file URLs. My receiver for the NSMetadataQueryDidFinishGatheringNotification looked like this:

- (void)queryDidFinishGathering:(NSNotification *)notification
{
    NSMetadataQuery *query = [notification object];
    [query disableUpdates];
    [query stopQuery]; //  <--- This was the problem

    NSMetadataItem *item = [query resultAtIndex:0];
    NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
    UIDocument *doc = [[CustomDocument alloc] initWithFileURL:url];
    [doc openWithCompletionHandler:^(BOOL success) {
         // EXC_BAD_ACCESS before completion block is called :'(
    }];

    [query enableUpdates];
}

Removing the stopQuery call fixed everything!

Neal Ehardt
  • 10,334
  • 9
  • 41
  • 51