Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDocument openWithCompletionHandler not completing on iOS device

I am trying to open a managed document using openWithCompletionHandler:

The problem I am coming across is that it works fine on the simulator, but when I test it on my iPhone 4 the completion handler never finishes. The code looks like this:

[theManagedDocument openWithCompletionHandler:^(BOOL success){
    if(success) [self documentIsReady];
    if(!success) NSLog(@"Couldn't Open Document");
}];

This works fine on the simulator and I get to the documentIsReady call (or the "Couldn't Open Document" if it errors). But on the iPhone 4 it never runs the CompletionHandler block. I've put breakpoints all through the block (before and after both if statements) and nothing is getting called. No "Couldn't Open Document" on the console, no call to documentIsReady.

I must also mention that it seems like the first time I run the app on the iPhone it will work properly. I also have this encapsulated in an if statement with a fileExistsAtPath: call. It is getting inside the if statement just fine and calling the openWithCompletionHandler:, but the completion block just never gets fired.

I am using iOS 5.1 and Xcode 4.3.2.

like image 509
Justin Paulson Avatar asked Apr 12 '12 15:04

Justin Paulson


3 Answers

I have experienced the same issue in my apps that use iCloud to share data. I realized that openWithCompletionHandler: just waits and never calls the completion handler if the document is left open by a suspended app. If that is the case for you, you should make sure that you are closing the document when your app goes to background.

like image 168
murat Avatar answered Nov 15 '22 23:11

murat


In my case, powering off my iPad and restarting it "fixed" this problem. Good luck!

like image 30
Dave Ross Avatar answered Nov 16 '22 00:11

Dave Ross


Try checking that theManagedDocument != nil before the call - that's the only reason I can think of why the block would not be executed.

like image 26
Nick Lockwood Avatar answered Nov 16 '22 01:11

Nick Lockwood