我正在使用RestKit进行web服务调用,缓存和etags。 我实现了我自己的coredata模型和managedObjectsiOS - RestKit并清除所有数据?
只要用户注销,我需要清除数据库中的所有数据。 我能够成功删除sqlite文件并重新创建它,但我找不到清除所有RestKit捕获和etag数据的方法。 如何完全清除RestKit存储的所有数据?
我正在使用RestKit进行web服务调用,缓存和etags。 我实现了我自己的coredata模型和managedObjectsiOS - RestKit并清除所有数据?
只要用户注销,我需要清除数据库中的所有数据。 我能够成功删除sqlite文件并重新创建它,但我找不到清除所有RestKit捕获和etag数据的方法。 如何完全清除RestKit存储的所有数据?
要拨打[[RKClient sharedClient].requestCache invalidateAll];
擦拭缓存清理。您可以查看API docs。
使用RKManagedObjectStore类中的以下方法。
- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile
在Restkit 0.20 试试这个:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
为我工作=)
在RestKit 0.20.2下面的例子是卓有成效的。它基于在RKTestFactory.m文件中的RestKit/Testing组件中找到的代码,并且在我的项目中运行良好。另外,如果RestKit管理你的CoreData堆栈,这是我如何设置的,记得要删除在你的RestKit设置中使用NSManagedObjectContext的任何NSFetchedResultsController。
- (void)tearDownRestKit
{
// Cancel any network operations and clear the cache
[[RKObjectManager sharedManager].operationQueue cancelAllOperations];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// Cancel any object mapping in the response mapping queue
[[RKObjectRequestOperation responseMappingQueue] cancelAllOperations];
// Ensure the existing defaultStore is shut down
[[NSNotificationCenter defaultCenter] removeObserver:[RKManagedObjectStore defaultStore]];
// Not be needed if not using indexer
if ([[RKManagedObjectStore defaultStore] respondsToSelector:@selector(stopIndexingPersistentStoreManagedObjectContext)]) {
// Search component is optional
[[RKManagedObjectStore defaultStore] performSelector:@selector(stopIndexingPersistentStoreManagedObjectContext)];
if ([[RKManagedObjectStore defaultStore] respondsToSelector:@selector(searchIndexer)]) {
id searchIndexer = [[RKManagedObjectStore defaultStore] valueForKey:@"searchIndexer"];
[searchIndexer performSelector:@selector(cancelAllIndexingOperations)];
}
}
[RKObjectManager setSharedManager:nil];
[RKManagedObjectStore setDefaultStore:nil];
}
作为RestKit 0.20您将需要使用'[[RKManagedObjectStore defaultStore] resetPersistentStores:nil];' –
使用RestKit 0.20为我工作http://stackoverflow.com/a/18425303/1318202 –
嗨@ blake-watters如何在0.20版本中做到这一点 –