Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've solved this problem, thanks to this post<a href="https://stackoverflow.com/a/2539547/1421549">iPhone: Can access files in documents directory in Simulator, but not device</a></p> <p>In this post he referenced this blog :<a href="http://majicjungle.com/blog/123/" rel="nofollow noreferrer">Xcode resource groups and folder references when building for iPhone</a></p> <p>After solving my problem, I've come to realize the reason that preload sqlite database won't work in device is: when Xcode copy database to the device from the bundle, the folder layers(myDB/StoreContent/persistentStore) wrapping the persistentStore is removed. So there is only a persistentStore file mixed with all other files in the device in the myApp.app bundle. And when you use UIManagedDocument to access sqlite database, it can only work with sqlite in such directory structure: myDB/StoreContent/persistentStore. So, with only a naked persistentStore file, the UIManagedDocument will create a whole new directory structure for you, with an empty persistentStore in it. </p> <p>If someone can suggest a way for UIManagedDocument to work with the persistentStore file without folder layers, I would be interested. </p> <p>And I use this code to access the DB after I successfully replicate the directory structure in my device bundle: </p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (!self.myDataBase) { NSURL *url = [[NSBundle mainBundle] resourceURL]; url = [url URLByAppendingPathComponent:@"myDB/"]; self.myDataBase = [[UIManagedDocument alloc] initWithFileURL:url]; } return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload