iOS – RestKit并清除所有数据?

我正在使用RestKit进行web服务调用,caching和etags。 我实现了我自己的coredata模型和managedObjects

只要用户注销,我需要清除数据库中的所有数据。 我能够成功地删除sqlite文件并重新创build它,但我找不到清除所有RestKit捕获和etag数据的方法。 我怎样才能完全清除由RestKit存储的所有数据?

你想调用[[RKClient sharedClient].requestCache invalidateAll]; 擦干净的caching。 您可以查看API文档 。

使用RKManagedObjectStore类中的以下方法。

- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

http://restkit.org/api/0.9/Classes/RKManagedObjectStore.html#//api/name/deletePersistantStoreUsingSeedDatabaseName

在Restkit 0.20中试试这个:

 [[NSURLCache sharedURLCache] removeAllCachedResponses]; 

为我工作=)

在RestKit 0.20.2中,下面的例子是诀窍。 它基于在RKTestFactory.m文件中的RestKit / Testing组件中find的代码,并且在我的项目中运行良好。

此外,如果RestKit正在pipe理你的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]; }