在模拟器上卸载应用程序后,NSUserDefaults未清除 [英] NSUserDefaults not cleared after app uninstall on simulator

查看:716
本文介绍了在模拟器上卸载应用程序后,NSUserDefaults未清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能听起来真的是NOOB!我想检查是否是用户第二次进入我的应用程序,所以要保持运行计数我正在使用 NSUserDefaults 。我在 rootViewController viewDidLoad 方法中实现了以下代码:

  NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; 

NSLog(@hello%ld,(long)[userDefaults integerForKey:@runCount]);

if([userDefaults integerForKey:@runCount]!= 1){
//不是第二次运行
[userDefaults setInteger:1 forKey:@runCount] ;
NSLog(@不是第二次运行);
} else {
//第二次运行或更多
NSLog(@第二次运行);
}

[userDefaults synchronize];

一切正常,但问题是当我卸载(删除并重新安装)应用程序时根据此处此处数据应该被清除,但事实并非如此,在重新安装应用程序之后,以前的数据仍然显示出来。
我在iOS模拟器上运行我的应用程序使用xCode6-beta并在iOS 8上定位应用程序

解决方案

我认为这是由于iOS8 Beta模拟器中的一个错误。



预期的行为是,当删除应用程序时,该应用程序的NSUserDefaults也会被删除。 / p>


  • 但是,当您从模拟器中删除应用程序时,NSUserDefaults被 NOT 删除。

  • 从运行iOS8的物理设备中删除它们时会被正确删除。



现在快速而烦人的解决方案是单击,iOS模拟器 - >重置内容和设置。



Xcode 9.2 with Simulator 10仍然存在此问题。菜单选项现在是硬件..删除所有内容和设置



我提交了错误报告btw


this may sound real NOOB! I want to check if it's the second time the user enters my application, so to keep the run count I'm using NSUserDefaults. I have implemented the following code in my rootViewController's viewDidLoad method:

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"hello %ld", (long)[userDefaults integerForKey:@"runCount"]);

    if ([userDefaults integerForKey:@"runCount"] != 1) {
        //not the 2nd run
        [userDefaults setInteger:1 forKey:@"runCount"];
        NSLog(@"not 2nd run");
    } else {
        //second run or more
        NSLog(@"2nd run");
    }

    [userDefaults synchronize];

everything works fine, but the problem is that when I uninstall(delete and re-install) the application according to here and here the data should be cleared, but it is not and after re-installing the app previous data is still showing up. I'm running my app on iOS simulator using xCode6-beta and targeting the application on iOS 8

解决方案

I think this is due to a bug in the iOS8 Beta Simulator.

The expected behavior is that when the app is deleted, the NSUserDefaults for that app are deleted as well.

  • However, NSUserDefaults are NOT deleted when you remove an app from the simulator.
  • They are correctly deleted when you delete them from a physical device running iOS8.

A quick and annoying solution for now is to click, iOS Simulator -> Reset Content and Settings.

Xcode 9.2 with Simulator 10 still presents this issue. Menu option is now Hardware .. Erase All Content and Settings

I submitted a bug report btw

这篇关于在模拟器上卸载应用程序后,NSUserDefaults未清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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