Access keychain data from Apple Watch
Asked Answered
K

3

7

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?

Kaye answered 5/3, 2015 at 4:14 Comment(0)
A
4

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.

https://forums.developer.apple.com/thread/5938

Arvid answered 24/10, 2015 at 11:41 Comment(0)
S
4

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?

Stipple answered 5/3, 2015 at 6:38 Comment(1)
Just a note for those looking for keychain sharing between iOS and watchOS 2+. Keychain sharing is NOT available between the WatchKit extension (on watchOS 2+) and its companion iOS app, so you will need to use another way to transfer data between those devices, like the new WatchConnectivity framework. forums.developer.apple.com/thread/5938Sikorsky
A
4

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.

https://forums.developer.apple.com/thread/5938

Arvid answered 24/10, 2015 at 11:41 Comment(0)
F
-5

The way to do it is to use App Groups and NSUserDefaults. Click on your main target project, find Capabilities and then App Groups

enter image description here

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];
Flaminius answered 23/5, 2015 at 4:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.