1

I have an iOS app that uses an SQLite database. This works very good. Now I added a WatchKit App Extension and would like to connect to that existing database which resides in the Documents folder of my iPhone app.

Can someone please show me how to do this?

I already created an app-group (same for all the extensions).

If it matters, the iOS app is written in Objective-C, and the watch app is written in Swift.

Screenshot of iPhoneApp and WatchApp

Jurgen Dictus
  • 346
  • 3
  • 15

1 Answers1

2

Since watchOS 2, the watch app can no longer access data in the shared app group, since the watch app extension now runs on the watch instead of the iPhone.

A shared app group won't accomplish what you want. You'll have to use Watch Connectivity to accomplish what you want.

Approach 1:

Maintain two separate databases — one on the phone, and one on the watch — and keep the two separate databases in sync.

This would be useful if the watch needed access to any and all data, and must operate independently of the phone, if it was out of reach.

transferUserInfo would be a good fit for this approach, to sync new, updated, or deleted dive plans between the phone and the watch.

You could also transfer the entire database between the phone and the watch, but this generally is less energy efficient than just sending changes.

Approach 2:

Only transfer the current context to the watch, so the user could glance at the watch to see the same information that the phone would have been showing.

For something like your dive app, perhaps it only transfers a recent or upcoming dive plan, instead of showing every dive plan on the smaller screen.

updateApplicationContext would be a good fit for this approach, to pass the most recent information that should be shown on the watch.

Community
  • 1
  • 1