0

My purpose is to retrieve a UIManagedDocument object from an known url and then open it.

Something like:

 UImanagedDocument *doc = retrieveDoc(url);

then, I can do something like:

 [doc openWithCompletionHandler:^(BOOL success){ ....}];

Believe me I did search apple's documentation there is a only method called initialise with a given url. Yes, I init create and save it before, and later I just need pick it up. Any way to do this?

Hope any one could give hints, thanks

WHT
  • 63
  • 1
  • 7
  • for example: "- (BOOL)readFromURL:(NSURL *)url error:(NSError **)outError" Is this should be a class method? Then it will be what I want... – WHT May 01 '12 at 14:35

1 Answers1

0

There should be such a class method, but in apple's reference, I found the sample code for creating UIManagedDocument

 doc = [[UIManagedDocument alloc] initWithFileURL:docURL];
 if ([[NSFileManager defaultManager] fileExistsAtPath:[docURL path]]) {
[doc openWithCompletionHandler:^(BOOL success){
    if (!success) {
        // Handle the error.
    }
}];
}
else {
[self addInitialData];
[doc saveToURL:docURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){
    if (!success) {
        // Handle the error.
    }
}];

So, basically, every time I want retrieve a UIManagedDocument from a given url, I must init it first and then open it. Am I right?

Any way, this is the way what I found working till now.

WHT
  • 63
  • 1
  • 7