Passing data to Apple Watch app

后端 未结 5 926
天涯浪人
天涯浪人 2020-11-29 03:34

I am trying to pass data from my app into my Apple Watch app. Basically, I am using the same method as I used for creating the today widget and so I am passing data through

5条回答
  •  广开言路
    2020-11-29 04:08

    This applies to OS 1 only. See below for better answers.

    I got it working using your method. I guess there's a couple of things you can check:

    1) Are you synchronising the defaults after you set the value:

    defaults?.synchronize();
    NSLog("%@ ", defaults?.dictionaryRepresentation())
    

    2) Have you enabled the App Group in both your app and your extension?

    App Group capability for App Target App Group capability for Watch Extension Target

    3) Are you using the correctly named app group when constructing the NSDefaults? For example, I use:

    NSUserDefaults(suiteName: "group.com.brindysoft.MyWatch");
    

    Once all that's set up I run the app, set the value in the defaults, then run the glance target which reads the value from the default and that seems to work!

    1. Still stuck? check your app groups in your apple account

提交回复
热议问题