2011-08-26 40 views
10

私はWebサービス呼び出し、キャッシュ、etagsにRestKitを使用しています。 私自身のcoredataモデルとmanagedObjectsを実装しましたiOS - RestKitとすべてのデータを消去しますか?

ユーザーがログアウトするとすぐに、データベース内のすべてのデータを消去する必要があります。 sqliteファイルを正常に削除して再作成できましたが、すべてのRestKitキャッチとエタグデータをクリアする方法が見つかりません。 RestKitによって保存されたすべてのデータを完全に消去するにはどうすればよいですか?

答えて

14

あなたはきれいにキャッシュを拭くために[[RKClient sharedClient].requestCache invalidateAll];を呼びたいです。 API docsを見ることができます。 )=

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 

が私のために働いたRestKit 0.20.2では

+8

RestKit 0.20以降では、[[RKManagedObjectStore defaultStore] resetPersistentStores:nil]; ' –

+0

を使用する必要があります。RestKit 0.20を使用して私のために働きましたhttp://stackoverflow.com/a/18425303/1318202 –

+0

こんにちは@ blake-wattersそれは0.20バージョンで行う –

4

RKManagedObjectStoreクラスから次のメソッドを使用します。

- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

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

+0

私のシードファイルは何ですか?私は自分のコアデータモデルとコンテキストを持っていますが、私はrestkitを使用していません – aryaxt

+1

その場合、あなたの質問はここで答えられました:http://stackoverflow.com/questions/1077810/delete-reset-all-entries-in- core-data –

+0

私は彼らがキャッシュとetagsを同じsqliteファイルに格納しているとは思わない。現在、私は自分のsqliteを削除して再作成し、Webサービスを呼び出すと、RestKitは以前のキャッシュデータを返します。したがって、私は古いデータで再び終わります。 – aryaxt

2

Restkit 0.20 ではこれを試してみてください。これは、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]; 
} 
0

次の例では、トリックを行います。

関連する問題