Unable to get values from settings bundle in watchOS 2

一笑奈何 提交于 2019-12-02 04:55:47

问题


I have a settings bundles that I use with my watch app. I am migrating my app to watchOS 2. Does anyone know how setting bundles are supposed to work? Does the iPhone transfer the values to a the standard user defaults or to a user defaults with a suite name for a shared app group? I can't get either to work and I can't find any documentation on how setting bundles are supposed to work with watchOS 2.


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/31809925/unable-to-get-values-from-settings-bundle-in-watchos-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!