iOS - RestKit 并清除所有数据?

发布于 2024-12-01 18:01:04 字数 190 浏览 1 评论 0原文

我使用 RestKit 进行 Web 服务调用、缓存和 etag。 我实现了自己的 coredata 模型和 ManagedObjects

一旦用户退出,我就需要清除数据库中的所有数据。 我能够成功删除 sqlite 文件并重新创建它,但我找不到清除所有 RestKit 捕获和 etag 数据的方法。 如何彻底清除 RestKit 存储的所有数据?

I am using RestKit for webservice calls, caching, and etags.
I implemented my own coredata model and managedObjects

As soon as the user signs out I need to clear all data in the database.
I was able to successfully delete the sqlite file and recreate it, but I can't find out a way to clear all RestKit catching and etag data.
How can I completely wipe all data stored by RestKit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦中的蝴蝶 2024-12-08 18:01:04

您想要调用 [[RKClient sharedClient].requestCache invalidateAll]; 将缓存擦除干净。您可以查看API 文档

You want to call [[RKClient sharedClient].requestCache invalidateAll]; to wipe the cache clean. You can view the API docs.

梦途 2024-12-08 18:01:04

使用 RKManagedObjectStore 类中的以下方法。

<代码>
- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

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

Use the following method from the RKManagedObjectStore class.


- (void)deletePersistantStoreUsingSeedDatabaseName:(NSString *)seedFile

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

薄荷梦 2024-12-08 18:01:04

在 Restkit 0.20 中
试试这个:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

对我有用=)

In Restkit 0.20
try this:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

worked for me =)

め可乐爱微笑 2024-12-08 18:01:04

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

In RestKit 0.20.2 the following example does the trick. Its based off code found in the RestKit/Testing component in the file RKTestFactory.m and has worked great in my project.

Also, If RestKit is managing your CoreData stack, which is how mine is set up, remember to delete any NSFetchedResultsController that are using the NSManagedObjectContext in your RestKit setup.

- (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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文