I don't think you should mess around with the files and directories yourself in iOS.
You can, however, open the document directly from your bundle. For that, you simply have to copy the whole document directory you created in your Loader app into your final bundle. The structure should be rather simple, just two directories with the persistentStore file inside.
Afterwards, when you want to open your document, you need to take care of two things: you need to use the bundle directory as the base directory and you need to add a /
at the end of the "file" name, so UIManagedDocument
knows that the directory is the document. The code looks like this:
NSURL* url = [[NSBundle mainBundle] bundleURL];
url = [url URLByAppendingPathComponent:@"filename/"];
UIManagedDocument* doc = [[UIManagedDocument alloc] initWithFileURL:url];
Note that you cannot write to that file, as you are not allowed to write inside your application bundle. So if you want to have a writable document, you need to copy that document into your documents folder. You can do that easily by simply saving doc
to a different location:
[doc saveToURL:newURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){}]
One more thing: You have to make sure the folder structure is created in your app bundle. The easiest way to make this happen is to drag the whole folder into your project and then select "Create folder references for any added folders". For the "file" symbollist_en
(which is actually a bundle/folder itself) it should look like this:
If you do not do this, the "contents" of the document will reside in your app bundle directly, which cannot be opened as a UIManagedDocument
, as you found out.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…