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

查看:21
本文介绍了Apple 是否将 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?

那里 a lot of stackoverflow 上关于这个主题的问题,所有问题都有相同的答案.也就是说,例如

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 文档.有

此外,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.

我有两个问题:

  • 哪个是正确的:我上面提到的所有 StackOverflow 问题的答案,或者是 Apple 文档

  • 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 应用程序的方式).在 watchOS 中,Apple 添加了 WatchConnectivity,这是 iOS 和手表应用程序之间共享数据的标准.

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.

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

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