简体   繁体   English

从iOS共享AsyncStorage与Apple Watch响应本机应用

[英]Share AsyncStorage from iOS react native app with Apple Watch

I'm developing the main app with react native and the Apple Watch with Swift. 我正在使用react native开发主要应用程序,并使用Swift开发Apple Watch。

The main app (react native) uses AsyncStorage to store some values, that then are used as params for a fetch that shows a list. 主应用程序(反应本机)使用AsyncStorage存储一些值,然后将这些值用作显示列表的访存的参数。

After running the simulator, I found manifest.json inside 运行模拟器后,我在里面找到manifest.json

~/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. 我需要在Xcode的Apple Watch中访问这些值,以完成与iOS应用程序相同的工作。 How do I access that data? 如何访问这些数据?

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. 由于Apple Watch应用程序自watchOS 2起独立于iOS应用程序运行,因此实际上无法直接访问iPhone本地存储的数据-您需要在iOS和watchOS应用程序之间保持某种形式的通信。

The framework intended for this is called WatchConnectivity . 用于此目的的框架称为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. 每当文件更新时,使用transferFile将文件从iOS设备传输到Apple Watch。 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. 或者,您可以只使用updateApplicationContext来传递已经序列化的数据,而不是传输原始的JSON文件-同样,这在很大程度上取决于您的特定需求。

Unfortunately, I don't know how WatchConnectivity is supposed to work with ReactNative. 不幸的是,我不知道WatchConnectivity应该如何与ReactNative一起工作。 If you want a deeper introduction to this framework — I highly recommend watching this amazing video from WWDC 2015. 如果您想对该框架进行更深入的介绍,我强烈建议您观看WWDC 2015的精彩视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AsyncStorage 参考崩溃在 iOS 上对本机应用程序做出反应 - AsyncStorage reference crashes react native app on iOS 是否可以从Apple Watch应用程序共享文本? - is it possible to share text from apple watch app? React Native Share Extension - 访问 AsyncStorage? - React Native Share Extension - Access to AsyncStorage? 从iOS中的“共享”按钮启动应用-Objective C和React Native - Launch app from share button in iOS - Objective C and React Native 来自React Native的AsyncStorage中的Prom - Promises in AsyncStorage from React Native 将原生iOS应用程序的数据迁移到React Native应用程序的异步存储 - Migrating native iOS app's data to React Native app's asyncstorage 如何以编程方式从iOS应用程序打开Apple Watch伴侣应用程序 - How to programmatically open Apple Watch companion app from iOS app 我可以从iOS App切换到Apple Watch吗? - Can I handoff from iOS App to Apple Watch? 当我尝试从React Native iOS应用程序共享我的应用程序URL时,应用程序变得无响应 - App becomes unresponsive when I tried to share my app url from react native iOS app 在watchOS4中从Apple Watch应用程序到iPhone应用程序共享实时数据的最佳方法是什么? - Whats the best way to share real time data from an apple watch app to iphone app in watchOS4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM