Gokulnath
Gokulnath

Reputation: 235

Apple watch - Storing data to Apple Watch separately without dependence on iPhone

I am working on an app which consists of an Apple Watch component. Once the iPhone app is launched, it will send information (device id, IP address, etc.) to Apple Watch via the WatchConnectivity framework and data will be stored to user defaults. The Apple Watch will use the information to send data to the server. But in some scenarios, the values from NSUserDefaults returns as "null". For example

  1. When the watch is switched on and off.
  2. When the app is killed and not opened etc.

Please give some suggestions for storing data on Apple Watch permanently and without being dependent on iPhone every time.

Upvotes: 2

Views: 159

Answers (2)

juhan_h
juhan_h

Reputation: 4011

I am storing stuff in the watch's filesystem by serializing/deserializing my custom objects by implementing NSCoding and using NSKeyedArchiver and NSKeyedUnarchiver.

Upvotes: 3

David Pasztor
David Pasztor

Reputation: 54726

Depending on the complexity of the data you want to store, it might be worth using a database framework (i.e. Realm or CoreData) to store persistent data on the watch.

Upvotes: 2

Related Questions