在 iPhone 和 iPad 版本之间共享通用二进制文件中的 NSUserDefaults
这是我第一次尝试在一个项目中为 iPhone 和 iPad 创建两个目标。
我的问题是,如果我将数组保存到 NSUserDefaults,并且 iPhone 与 iTunes 同步,然后我同步 iPad,iPad 版本是否可以访问与其同步的数组?
This is my first stab at creating two targets within one project for iPhone and iPad.
My question is, if I save an array to NSUserDefaults, and the iPhone syncs with iTunes, and then I sync the iPad, will the iPad version have access to the array synced to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您要么有一个通用二进制文件,要么有两个不同的目标。
就同步而言,我认为它以不同的方式同步每个设备 - 即使两部 iPhone 也应该有单独的默认值。
You either have a universal binary or you have two different targets.
As syncing is concerned, I think it syncs each device differently - even two iPhones should get separate defaults.
虽然 iTunes 会备份默认设置,但它不会将它们推送回设备 - 它只同步少数内容(音乐/等、联系人、日历...)。
还不清楚您希望如何保持同步。假设您更改两台设备上的默认设置,然后同步它们。会发生什么?
如果您感觉特别反常,您可以将默认值编码到一个专门命名的联系人中(并且有一个“带我回家”应用程序将“家庭”位置存储在一个专门命名的联系人中, IIRC)。这可能会导致编辑冲突;我认为 iTunes 会告诉用户这一点,并让他们通过决定保留哪个版本来解决问题。
但我真的不想依赖 iTunes 同步。我连续几个月没有同步(或者等待 iTunes 进行备份——当手机本身变砖时很烦人)。
While iTunes backs up defaults, it doesn't push them back to the device — there are only a handful of things that it syncs (music/etc, contacts, calendar, ...).
It's also unclear how you want to keep things in sync. Let's say you change the default on both devices, and then sync both of them. What happens?
If you're feeling particularly perverse, you can encode the default into a specially-named contact (and there's a "take me home" app that stores the "home" location in a specially-named contact, IIRC). Presumably this results in an edit conflict; I think iTunes tells the user this and lets them fix the problem by deciding which version to keep.
But I really wouldn't want to rely on iTunes syncing. I go for months without syncing (or waiting long enough for iTunes to make a backup — annoying when the phone bricks itself).