简体   繁体   English

从设备删除应用程序不会清除NSUserDefaults

[英]Deleting app from a device doesn't clear NSUserDefaults

I'm storing a value in NSUserDefaults that I use to check if it's the first time the app has been launched. 我在NSUserDefaults中存储了一个值,用于检查它是否是第一次启动应用程序。 I check this value in my App Delegate and it works fine for the most part. 我在App Delegate中检查了这个值,它在大多数情况下都能正常工作。 However, I expected that this value would clear if I deleted the app from the device so that when launched the first time after being reinstalled it would behave as though it had never been installed on that device. 但是,我预计如果我从设备中删除了应用程序,这个值就会清除,以便在重新安装后第一次启动它时,它的行为就好像从未在该设备上安装过一样。 However, the value stored in NSUserDefaults is still there. 但是,存储在NSUserDefaults中的值仍然存在。 Now I know how to clear NSUserDefaults programmatically but how would I do this and still be able to tell if it's the first time the app has been launched (and have the first time launched after being deleted be detected as a first launch)? 现在我知道如何以编程方式清除NSUserDefaults,但是我怎么能这样做并且仍然可以判断它是否是第一次启动应用程序(并且在删除后第一次启动时被检测为第一次启动)?

Edit: This issue was for an actual physical device (not the simulator). 编辑:此问题适用于实际的物理设备(不是模拟器)。 Deleting the app from the simulator DID clear NSUserDefaults correctly. 从模拟器中删除应用程序DID正确清除NSUserDefaults。 However, I had my iPhone replaced yesterday and the new phone doesn't exhibit this issue. 但是,我昨天更换了我的iPhone,新手机没有出现这个问题。 NSUserDefaults is clearing correctly now. NSUserDefaults正在正确清除。 Don't know what fixed the problem but I'll take it. 不知道是什么解决了问题,但我会接受它。

For anyone facing the same issue on device. 对于在设备上遇到相同问题的任何人。

If you have more than 1 app under the same group and all of them are using app groups (ON under capabilities), then you will have to remove all the apps from the device in order for the user defaults to be cleared. 如果同一组下有多个应用程序且所有应用程序正在使用应用程序组(功能下为ON),则必须从设备中删除所有应用程序才能清除用户默认值。

Since the user defaults are shared, even if one of the app is on the device then it will not be deleted, as that app will be using the userdefaults. 由于用户默认值是共享的,即使其中一个应用程序在设备上,也不会被删除,因为该应用程序将使用userdefaults。

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

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