NSUserDefaults 在关闭应用程序时删除密钥
NSUserDefaults deleting keys when close the app
我需要在应用程序关闭时删除密钥。那我该怎么办?
使用以下代码从 NSUserDefaults
中删除密钥
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourKey"];
在您的 ApplicationDelegate
方法中,您的意思是 "close the app":
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillTerminate:(UIApplication *)application
查看文档
- removeObjectForKey:
删除标准应用程序域中指定默认键的值。
我需要在应用程序关闭时删除密钥。那我该怎么办?
使用以下代码从 NSUserDefaults
中删除密钥
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourKey"];
在您的 ApplicationDelegate
方法中,您的意思是 "close the app":
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillTerminate:(UIApplication *)application
查看文档
- removeObjectForKey:
删除标准应用程序域中指定默认键的值。