NSUserDefaults(suiteName:) on iOS 9 and WatchOS 2 - not working?

烂漫一生 提交于 2019-11-29 07:16:17

In watchOS 2 you need to keep in mind that there is 2 different processes running:

  1. Apple Watch Process
  2. iPhone Process

Both of these processes have their own sandbox that's why they call it "native", so if you try to use the shared NSUserDefaults it will not work because the Apple watch app has a completely different sandbox than the host iPhone app.

If you want to save something from your phone to the NSUserDefaults on the Apple watch Target:

Use WatchConnectivity to send the data you want to save to the watch. Then when the watch receives the data you sent to it, save it to the Apple watch's default NSUserDefaults.

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