user599807
user599807

Reputation:

Share sqlite database between app and extension

I have followed this tutorial and added my database. I did target both my app and my extension. From my app I can SELECT, INSERT, DELETE and UPDATE to the database. I want both my app and extension to share the same database. So I add information in my app and then show that information in the extension.

As it works now (I have tested) the app has one instance of the database and the extension has one instance. I have only added one db. Anyone got a clue why I have two instances of my database and why I can´t access the data added from the app in the extension?

Upvotes: 6

Views: 3552

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70976

Apps and their extensions are separate processes, so iOS sandboxing normally means they can't touch each other's files. The page you reference doesn't appear to address this in any way.

If you want to use the same SQLite file in both your app and the extension, you need to configure the "app groups" entitlement for both of them. That sets up a new directory that both of them can access, and you put your SQLite file there. You find this directory by using the containerURLForSecurityApplicationGroupIdentifier: method on NSFileManager.

It's not clear to me whether the GitHub project you're using will make use of app groups. There's no other way to share your SQLite file, though. If that project doesn't use app groups, you'll need to either fix it so that it does or stop using it.

Upvotes: 9

Related Questions