简体   繁体   English

即使应用将被删除,如何在NSUserDefaults中保存数据?

[英]How to save data in NSUserDefaults even if app will be deleted?

I save some strings and numbers to NSUSerDefault, but when I uninstall and reinstall the app the data is ereased. 我将一些字符串和数字保存到NSUSerDefault,但是当我卸载并重新安装该应用程序时,数据会增加。

Is there a possibility to store data some where else? 是否有可能在其他位置存储数据? Maybe in keychain? 也许在钥匙串中?

There are two places where you can store data that will persist after an app is deleted, but in both cases, it's not hidden data, so if that's what you're looking for, you're out of luck. 您可以在两个地方存储数据,这些数据在删除应用程序后将继续存在,但是在两种情况下,它都不是隐藏数据,因此,如果您要查找的是数据,那您就不走运了。

Your two possibilities are 1) Saving data to the photo library. 您有两种可能:1)将数据保存到照片库。 (However, you can't read it back unless you get the user to select the photo for you.) 2) The address book. (但是,除非让用户为您选择照片,否则您将无法将其读回。)2)地址簿。 This is one place where you can create an entry and select it without user input. 在这里,您可以创建条目并选择它而无需用户输入。

You could stash a small amount of data in the comments field of a keychain record. 您可以在钥匙串记录的注释字段中存储少量数据。

However, I doubt Apple would allow it because it would violate the principle of sandboxing the apps. 但是,我怀疑苹果公司会允许这样做,因为它违反了对应用程序进行沙箱处理的原则。 It's hard to think of a legitimate reason to have an app leave data behind after it's gone. 很难想到有一个合理的理由让应用程序在数据消失后将数据遗留下来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM