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.
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.
In my case, powering off my iPad and restarting it "fixed" this problem. Good luck!
Try checking that theManagedDocument != nil before the call - that's the only reason I can think of why the block would not be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With