有没有办法清除从应用程序安装存储的所有数据?
我有一个iOS应用程序,它将数据存储在NSUserDefults
并且许多其他数据由于Web视图加载,社交媒体签名等而被设置在caching中。我想从应用程序创build的caching中删除所有数据。
有没有办法在iOS中以编程方式执行此操作?
尝试
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
要么
[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
你可以试试这个
NSUserDefaults的
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
要么
NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; NSDictionary * dict = [defs dictionaryRepresentation]; for (id key in dict) { [defs removeObjectForKey:key]; } [defs synchronize];
UIWebviewcaching
[NSURLCache sharedURLCache] removeAllCachedResponses];
//删除cookies
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { if([[cookie domain] isEqualToString:someNSStringUrlDomain]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } }
尝试这个,
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"defunctPreference"];
一些caching与其他应用程序的信息连接。 删除它们时应该小心。 只是提醒你在操作之前检查。 我曾经犯过类似的愚蠢错误。 如果你find了一个很好的工具。 请分享! 谢谢。
你可以尝试使用[[NSURLCache sharedURLCache] removeAllCachedResponses];
有关更多详细信息,请参阅链接http://iphonedevsdk.com/forum/iphone-sdk-development/104198-programmatically-clearing-app-cache.html
如果你使用NSUserDefaults
,你可以试试这个 。
就其他caching文件而言,我认为你应该把它们全部保存在一个文件夹中,这样通过删除整个caching文件夹就可以很容易地删除它们。