Home Share AsyncStorage from iOS react native app with Apple Watch
Reply: 1

Share AsyncStorage from iOS react native app with Apple Watch

João Belo
João Belo Published in 2018-01-13 02:32:10Z

I'm developing the main app with react native and the Apple Watch with Swift.

The main app (react native) uses AsyncStorage to store some values, that then are used as params for a fetch that shows a list.

After running the simulator, I found manifest.json inside

~/Library/Developer/CoreSimulator/Devices/D10E869B-040B-446F-9B8B-754F111442EC/data/Containers/Data/Application/AC837AFE-312B-4861-906D-EC9EEE7D029B/Document s/RCTAsyncLocalStorage_V1

with the data inside.

I need to access those values in the Apple Watch in Xcode to do the same job as the iOS app. How do I access that data?

Oleg Dreyman
Oleg Dreyman Reply to 2018-01-14 21:53:18Z

Since Apple Watch apps run independently from iOS app since watchOS 2, there’s really no way to directly access the data stored locally on iPhone — you’ll need to maintain some form of communication between your iOS and watchOS apps.

The framework intended for this is called WatchConnectivity. I see two more-or-less suitable solutions for your case:

  • Using transferFile to transfer your file from an iOS device to an Apple Watch whenever it got updated. The viability of this option highly depends on how big your file is.
  • Or you can just use updateApplicationContext to pass an already serialized data instead of transferring a raw JSON file — again, highly depends on your specific needs.

Unfortunately, I don’t know how WatchConnectivity is supposed to work with ReactNative. If you want a deeper introduction to this framework — I highly recommend watching this amazing video from WWDC 2015.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303305 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO