Unable to get values from settings bundle in watchOS 2

时光怂恿深爱的人放手 提交于 2019-12-02 03:43:31

In Watch OS 2.0 since the Watch App extension is in the Apple Watch (not in the iOS App as in Watch 1.0) you can't transfer data through user defaults, so you should use instead WatchConnectivity. If you have a settings bundle or a framework and you want to use it in the AW App extension and in the iOS APP, you should import it in every target of your project.

spybart

The accepted answer is wrong. You can use Shared App Groups for the Settings bundle on WatchOS 2 and access the values via NSUserDefaults. No Watch Connectivity required. It is just tricky to set up and the official documentation is missing crucial info.

Recently discovered how to do it in my question here.

The 2 important points are:

  1. You need to enable Shared App Groups on all 3 targets (iOS app, Watchkit app, WatchKit extension)
  2. It only works on the real device, not simulator. You might need to remove the app from both devices and reinstall to have it start working.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!