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?
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.
Related
I have an iOS app, and I would like the watchOS app to have synchronized data. Currently, the data is from Firestore, since it's also synced from the web, but I'm open to re-architecting the app.
Fundamentally, what I need is the ability to synchronize user data across all three platforms: watchOS, iOS, and the web.
Currently I have the iOS sending the data to watchOS, but on the Watch if I kill the app I lose all the state until I sync again. Ideally, the state would persist until there is a chance to sync again. So, there needs to be some persistence on watchOS. It seems there's a few options:
AppStorage / UserDefaults seems like it might work, although I've had problems with it not liking arrays and not finding expected values in Info.plist
CoreData seems like the most viable option from what I've seen so far, but a lot of code to synchronize data between watchOS and iOS and especially if I'm also trying to synchronize with Firestore
JSON seems like it's technically an option but a lot of code to serialize/deserialize
Both the watchOS and the iOS apps are SwiftUI, and I'm trying to determine how to keep them on the same page. I have apps on my Watch that seem to do this ok, but I'm having trouble figuring out how to do it myself.
I'm developing an app from scratch in Xamarin that is intended to be an upgrade from an existing app developed previously in xcode and already available on the app store (I haven't seen it, but I presume it's objective c). The new app needs to ingest data from the old app so the user transition experience is smooth. I don't currently know how the old data is stored on the iOS device, just that it is stored on the device and not in a more convenient location.
Assuming I need access to all the data the old app might have stored on the device, what are my options? Can I release it as a separate app and somehow ingest the old data? Do I have to release it as the same app to the app store to gain access to the old data? Am I going to have to consider the harder route of updating the old app to store the data in a special way or in the cloud so the new app can then access it?
While I'm doing this is Xamarin, I'm fine with answers that discuss what Apple provides and how iOS works in this instance, and I'll figure out what that means for Xamarin, but Xamarin specific answers would be greatly appreciated.
Im a bit new to IOS and Swift. I generally use Cordova and let the "magic" behind the curtains unfold when building IOS apps. It seems, however, that developing for Apple Watch using watch kit isn't so "magical".
What I am trying to do is access authentication information via my watch, that was entered into my IOS app; then utilize that info to make API requests which I will parse and present in the apple watch. I don't want users to authenticate using the watch, hence there is some handshaking that needs to be done. Please help, not sure where to get started...
So, I used MMWormholeSession with Cordova in conjuction with WCSession. I had to do some modifications to the MMWormhole code, but all the puzzle pieces were in there.
I want to ask about how to use NSUserDefaults on the watchOS app.
Is its data different from the iOS app's NSUserDefaults's data?
There are a lot of stackoverflow questions about this topic and all of them have same answers. That said, for example
Watch apps that shared data with their iOS apps using a shared group
container must be redesigned to handle data differently. In watchOS 2,
each process must manage its own copy of any shared data in the local
container directory. For data that is actually shared and updated by
both apps, this requires using the Watch Connectivity framework to
move that data between them.
However, all the quoted text disappeared from the web page referred, see this accepted answer.
Instead, in current Apple Docs. There is
Additionally, iOS automatically forwards a read-only copy of your iOS
app’s preferences to Apple Watch. Your WatchKit extension can read
those preferences using an NSUserDefaults object, but it cannot make
changes directly to the defaults database.
I have 2 questions:
Which one is correct: all of StackOverflow questions' answers I mentioned above, or, the Apple Docs
Which mechanism iOS use to forward NSUserDefaults object to watchOS app? Is it reliable to be relied on for future development and how recent the data is up to date? Can this feature be deprecated in the near future?
Many thanks
To answer your first question, both answers you quoted from StackOverflow and Apple are correct. Apple forwards the iOS app's NSUserDefaults as read-only values, but the watch has it's own NSUserDefaults for its preferences. The main takeaway from the documentation is for watch apps to move away from shared container groups that use NSUserDefaults, (as this was how WatchKit apps were implemented). In watchOS, Apple has added WatchConnectivity which is the standard for sharing data between the iOS and watch apps.
To answer your second question, rely on NSUserDefaults as you would normally to store preferences related to each app separately and use WatchConnectivity for sharing data between apps.
If I'm not wrong, the App Watch can't take locations itself and needs to request it to the iPhone, so the current location is got in the WatchKit extension at iOS side... right?
I think this is a quite common thing WatchKit developers would do, but I don't find a clear tutorial/example of it, could somebody tell me one or post me some code? In addition, do you know if the way to deal with locations changes in watchOS 2?
EDIT: I've found that in some posts it is said that CoreLocation can be accessed from the WatchKit extension, and in others I've read that only the iOS app can... which is the correct?
You can access CoreLocation and all its methods directly from WatchKit itself. There's no need to employ any sort of additional logic, such as opening the parent app.
In watchOS 1, your WatchKit app is technically running on the iPhone, and you can therefore use (almost) any frameworks available to you on the iPhone (such as CoreLocation).
In watchOS 2, the WatchKit app is running on the Watch itself. I have done some research and I've not found anything that indicates you will have to make any changes to your usage of CoreLocation, and I will therefore assume the frameworks automatically handle the communication between the iPhone and the Watch.
I'll update this answer if I find anything indicating that you will have to employ some other logic to make this work in watchOS 2.