2

I want to get data from userDefaults to use in an Apple Watch app. I'm currently using WatchConnectivity. But for making session, the viewdidload should be open. Then the Phone only sends the data to the Watch when the iPhone app is loaded (viewDidLoad). To solve this, I want to use appGroupUserDefaults. But it doesn't work when I try to load the data in override func awake(withContext context: Any?) like this.

let loadedButtonList = appGroupUserDefaults.object(forKey: "Buttontitles")
    if (loadedButtonList as? [String] != nil) {//do something}

It seems like loadedButtonList is nil. Can't I use appGroupUserDefaults in this watchOS version? And Does anyone know the way to share data like this without using WatchConnectivity??

harunaga
  • 309
  • 2
  • 12
  • Possible duplicate of [iPhone and Apple Watch not sharing App Group](https://stackoverflow.com/questions/46140731/iphone-and-apple-watch-not-sharing-app-group). In summary, no, there's no way to share `UserDefaults` between iOS and watchOS. – Dávid Pásztor Oct 02 '18 at 08:22

1 Answers1

3

You can't use App Groups to share data between phone and watch since WatchOS3.

You can use updateapplicationContext to guarantee the data will be passed to Apple Watch.

coolioxlr
  • 278
  • 1
  • 7