苹果是否将NSUserDefaults共享从iOS应用更改为watchOS应用 [英] Did Apple change NSUserDefaults sharing from iOS app to watchOS app

查看:101
本文介绍了苹果是否将NSUserDefaults共享从iOS应用更改为watchOS应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下如何在watchOS应用程序上使用NSUserDefaults. 它的数据与iOS应用程序NSUserDefaults的数据不同吗?

I want to ask about how to use NSUserDefaults on the watchOS app. Is its data different from the iOS app's NSUserDefaults's data?

那里 都是 很多

There are a lot of stackoverflow questions about this topic and all of them have same answers. That said, for example

观看使用共享组与其iOS应用共享数据的应用 必须重新设计容器以不同方式处理数据.在watchOS 2中, 每个进程都必须管理自己在本地的任何共享数据的副本 容器目录.对于实际共享和更新的数据 这两个应用程序,这都需要使用Watch Connectivity框架 在它们之间移动数据.

Watch apps that shared data with their iOS apps using a shared group container must be redesigned to handle data differently. In watchOS 2, each process must manage its own copy of any shared data in the local container directory. For data that is actually shared and updated by both apps, this requires using the Watch Connectivity framework to move that data between them.

但是,所有引用的文本从此已接受的答案

However, all the quoted text disappeared from the web page referred, see this accepted answer.

相反,在当前的 Apple Docs .有

此外,iOS会自动转发iOS的只读副本 应用程式对Apple Watch的偏好设定.您的WatchKit扩展程序可以读取 使用NSUserDefaults对象的那些首选项,但是它不能使 直接更改为默认数据库.

Additionally, iOS automatically forwards a read-only copy of your iOS app’s preferences to Apple Watch. Your WatchKit extension can read those preferences using an NSUserDefaults object, but it cannot make changes directly to the defaults database.

我有2个问题:

  • 其中一个是正确的:我上面提到的所有StackOverflow问题的答案,或者Apple Docs

  • Which one is correct: all of StackOverflow questions' answers I mentioned above, or, the Apple Docs

iOS使用哪种机制将NSUserDefaults对象转发到watchOS应用?依靠它进行未来开发是否可靠?数据的最新程度如何?可以在不久的将来不推荐使用此功能吗?

Which mechanism iOS use to forward NSUserDefaults object to watchOS app? Is it reliable to be relied on for future development and how recent the data is up to date? Can this feature be deprecated in the near future?

非常感谢

推荐答案

要回答第一个问题,您从StackOverflow和Apple引用的答案都是正确的. Apple将iOS应用程序的NSUserDefaults转发为只读值,但手表具有自己的NSUserDefaults作为其首选项.该文档的主要内容是使监视应用程序脱离使用NSUserDefaults的共享容器组(因为这是实现WatchKit应用程序的方式). Apple在watchOS中添加了WatchConnectivity,这是在iOS和Watch应用之间共享数据的标准.

To answer your first question, both answers you quoted from StackOverflow and Apple are correct. Apple forwards the iOS app's NSUserDefaults as read-only values, but the watch has it's own NSUserDefaults for its preferences. The main takeaway from the documentation is for watch apps to move away from shared container groups that use NSUserDefaults, (as this was how WatchKit apps were implemented). In watchOS, Apple has added WatchConnectivity which is the standard for sharing data between the iOS and watch apps.

要回答第二个问题,请像往常一样依靠NSUserDefaults分别存储与每个应用程序相关的首选项,并使用WatchConnectivity在应用程序之间共享数据.

To answer your second question, rely on NSUserDefaults as you would normally to store preferences related to each app separately and use WatchConnectivity for sharing data between apps.

这篇关于苹果是否将NSUserDefaults共享从iOS应用更改为watchOS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆