避免频繁的去写磁盘,可以将需要保存的数据在退出程序(杀进程)时,一起保存到磁盘上的文件中。
具体执行的是下面两个方法:(以下的两个方法最好在真机上模拟操作(会打印出log日志在调试界面),在模拟器上是不会进入的(不会打印log日志在调试界面))
- (void)applicationDidEnterBackground:(UIApplication *)application { /* Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */ NSLog(@"------------applicationDidEnterBackground"); [HConfigration writeConfigWithKey:@"k-in12" WithValue:[NSString stringWithFormat:@"%d", 12]]; [[HConfigration sharedManager] storeConfigData]; } - (void)applicationWillTerminate:(UIApplication *)application { /* Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. */ NSLog(@"------------applicationWillTerminate"); [HConfigration writeConfigWithKey:@"k-i" WithValue:[NSString stringWithFormat:@"%d", 18]]; [[HConfigration sharedManager] saveFileDic]; }
执行的顺序如下
2015-07-05 21:45:37.874 J_IPhone[1525:197654] ------------applicationDidEnterBackground
2015-07-05 21:45:37.963 J_IPhone[1525:197654] ------------applicationWillTerminate
与此同时,查看真机的decoment文件,可以看出,需要保存的数据已经写入到磁盘上。
over。
另外,今天在调试时,xcode一直进不去断点:(cleanall后,删除app,然后重新编译就可以进断点了)
Xcode调试代码时,有时会遇到断点不停的问题。一般来说是你的改动和Xcode编译出来的调试信息不一致造成的。
解决方法
1、先cleanall,再构建(Build)一遍;
2、如果方案一没有解决问题,可以选中Xcode的项目,在Finder中打开内容,删除*.pbxuser和*.mode1v3文件,重新打开project下端点。