Sharing String from iOS to WatchKit with App Groups

I'm trying to share a

string
from my iOS app to my
WatchKit-app
. I have enabled
App-Groups
for both the iOS app and the
WatchKit
extension
. Then, in my iOS app, I set a variable for the
UserDefaults
.


let defaults = UserDefaults(suiteName: "group.com.jacobcavin.appName")


Then in the

ViewController
, I set
defaults
to a string from the text of a TextField.


defaults?.set(textField.text!, forKey: "KEY")


Inside the iOS app, this works perfectly and I can access this and get the right value. But, inside the WatchKit app, I try to get the string.


let defaults = UserDefaults(suiteName: "group.com.jacobcavin.appName") let string = defaults?.string(forKey: "KEY")


But string

returns
nil. I've looked through tons of tutorials, and I have made sure that each target has the same group identifier, different Bundle Identifiers, and the entitlement .plist files are correct. Can you please help?
Answered by DTS Engineer in 270748022

Modern versions of watchOS run your WatchKit extension on the Apple Watch. As such, you can’t share content between your iOS app and your WatchKit extension via an App Group; you’ll have to use some sort of networking technology. Many folks use WatchConnectivity for this.

I've looked through tons of tutorials …

It sounds like those tutorials were written for an older version of watchOS, where the WatchKit Extension ran on the iPhone. This hasn’t been the case since watchOS 2.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

Modern versions of watchOS run your WatchKit extension on the Apple Watch. As such, you can’t share content between your iOS app and your WatchKit extension via an App Group; you’ll have to use some sort of networking technology. Many folks use WatchConnectivity for this.

I've looked through tons of tutorials …

It sounds like those tutorials were written for an older version of watchOS, where the WatchKit Extension ran on the iPhone. This hasn’t been the case since watchOS 2.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Sharing String from iOS to WatchKit with App Groups
 
 
Q