清空UserDefaults

方法1:找到所有的key然后remove掉

/**

 *  清除所有的存储本地的数据

 */  

- (void)clearAllUserDefaultsData  

{  

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  


NSDictionary *dic = [userDefaults dictionaryRepresentation];  

for (id  key in dic) {  

[userDefaults removeObjectForKey:key];  

    }  

[userDefaults synchronize];  

}  


方法二:清除持久域

/**

 *  清除所有的存储本地的数据

 */  

- (void)clearAllUserDefaultsData  

{  


NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];  

[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];  



}  

你可能感兴趣的:(清空UserDefaults)