简体   繁体   English

NSUserDefaults关闭应用程序时删除键

[英]NSUserDefaults deleting keys when close the app

I need to delete keys when application will close. 当应用程序关闭时,我需要删除密钥。 So what should I do? 所以我该怎么做?

Delete keys from NSUserDefaults using the following code 使用以下代码从NSUserDefaults删除密钥

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourKey"];

in your ApplicationDelegate method following which state are you meaning by "close the app": 在您的ApplicationDelegate方法中,通过“关闭应用程序”来确定您的状态是什么:

- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillTerminate:(UIApplication *)application

Look in the documentation 查看文档

- removeObjectForKey:

Removes the value of the specified default key in the standard application domain. 删除标准应用程序域中指定的默认密钥的值。

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

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