我正在使用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版本中做到這一點 –