0

I am trying to develop a watchOS 2 app to go along with my iOS app. The iOS app utilizes Core Data, and the Apple Watch app is simply going to be a "read only" client and display the data from the iOS app.

I have read a few things regarding managing two data stores, but that seems to be overkill. I just want to transfer the data to the watch app on launch then send background transfer if things change on the phone.

My question is how do I send this information to the watch app initially? I don't think I can send the actual data objects to the watch app. Do I need to convert the objects to a dictionary and send all of the relevant information via the WatchConnectivity API?

joern
  • 27,354
  • 7
  • 90
  • 105
kschins
  • 1,054
  • 1
  • 13
  • 26

1 Answers1

1

Your approach sounds good. Mirroring your CoreData database on your watch app would indeed be overkill if you don't play to change the data on the watch.

So using the Application Context to send the data via background transfer is the right choice. This has only one caveat: The updateApplicationContext method that you use to tranfer the data only accepts a dictionary of property list values. In other words, you can only send objects that you could add to a property list:

  • Array
  • Dictionary
  • String
  • Data (NSData)
  • Date (NSDate)
  • Integer
  • Floating-point value
  • Boolean

So, you'll have to convert your Core Data objects to dictionaries that contain only those types, before you can send them.

That's a bit of an effort, but you would have to do that anyway even if you wanted to mirror your database on the watch side, because with watchOS2 you cannot use App Groups anymore to share CoreData files.

joern
  • 27,354
  • 7
  • 90
  • 105