As the title of question, I just want to access data saved in keychain on iPhone from Apple Watch. Can I do that? and how?
Since watchOS 2.0 sharing keychain items between the watch and the paired device is no longer possible. The watch and the paired device are considered independent now. One can use WatchConnectivity as a workaround.
The Watchkit app is an extension that is running on the paired phone, so you can share Keychain data in the same way as you can share keychain with any other extension - by activating "Keychain sharing" in your applications capabilities.
See Share between an iOS extension and it's containing app with the keychain?
Since watchOS 2.0 sharing keychain items between the watch and the paired device is no longer possible. The watch and the paired device are considered independent now. One can use WatchConnectivity as a workaround.
The way to do it is to use App Groups and NSUserDefaults. Click on your main target project, find Capabilities and then App Groups
Create a group with your project name, group.myproject, that way you will be able to share data across the Watch and iPhone. In your code, you can use this to retrieve a value:
NSUserDefaults *standardUserDefaults = [[NSUserDefaults alloc] initWithSuiteName: <YOUR_APP_GROUP>];
NSString *value = [standardUserDefaults objectForKey:YOUR_KEY];
© 2022 - 2024 — McMap. All rights reserved.