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?

3 Answers3

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?

Community
  • 1
  • 1
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • 4
    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](https://developer.apple.com/library/watchos/documentation/WatchConnectivity/Reference/WatchConnectivity_framework/index.html) framework. https://forums.developer.apple.com/thread/5938 – Alexandre OS Oct 22 '15 at 14:50
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

Evgenii
  • 36,389
  • 27
  • 134
  • 170
-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];
pgardunoc
  • 331
  • 2
  • 8