2014-11-25 42 views
2

我有一个iOS应用程序,它将数据存储在NSUserDefults中,并且许多其他数据由于Web视图加载,社交媒体签名等而设置在缓存中。 我想从应用程序创建的缓存中删除所有数据。有什么方法可以清除应用程序安装中存储的所有数据?

有没有办法在iOS中以编程方式执行此操作?

+0

此链接已经涵盖了您的问题:[链接](http://stackoverflow.com/questions/10460690/can-i-programmatically-wipe-the-application-data-in-applicationdidfinishlaunchin) – 2014-11-25 09:43:37

回答

0

您可以尝试使用[[NSURLCache sharedURLCache] removeAllCachedResponses];

有关详细信息,请参阅链接http://iphonedevsdk.com/forum/iphone-sdk-development/104198-programmatically-clearing-app-cache.html

+0

但没有运气: - ( – Neenu 2014-11-25 09:51:57

+0

'Caches'文件夹未得到清除 – Neenu 2014-11-25 09:54:10

+0

如果您尝试使用[link](http://stackoverflow.com/questions/15064854/delete-files-from-nscachesdirectory-programmatically),该怎么办? – 2014-11-25 10:01:02

0

如果使用NSUserDefaults,您可以尝试this

就其他缓存文件而言,我认为您应该将它们全部保留在一个文件夹中,以便通过删除整个缓存文件夹来轻松删除它们。

1

你可以试试这个

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]; 

UIWebView的缓存

[NSURLCache sharedURLCache] removeAllCachedResponses]; 

//删除cookie

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { 

    if([[cookie domain] isEqualToString:someNSStringUrlDomain]) { 

    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; 
    } 
} 
2

尝试

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; 
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; 

[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]]; 
1

尝试此,

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"defunctPreference"]; 
1

一些高速缓存都与其他应用的连接Informa公司灰。删除它们时应该小心。只是提醒你在操作之前检查。我曾犯过类似的愚蠢错误。如果你找到了一个好工具。请分享!谢谢。