【发布时间】:2015-01-27 09:35:24
【问题描述】:
在 RestKit 版本 0.23.x 上,我尝试在用户注销时重置核心数据的持久存储,使用以下方法:
// Cancel all requests
[[RKObjectManager sharedManager] cancelAllObjectRequestOperationsWithMethod:RKRequestMethodAny matchingPathPattern:@"/"];
[[RKObjectManager sharedManager].operationQueue cancelAllOperations];
[RKObjectManager sharedManager].managedObjectStore.managedObjectCache = nil;
// Clear our object manager
[RKObjectManager setSharedManager:nil];
// Reset our persistent store
[[RKManagedObjectStore defaultStore] resetPersistentStores:nil];
// This command runs the reconfiguration of RestKit, the same
// code that is applied when the app launches.
[self setup]
但是,当我重新登录时,RestKit 无法映射响应:
2015-01-27 10:28:16.452 <APP_NAME>[80341:12445388] I restkit.network:RKObjectRequestOperation.m:220 GET '<api url>' (200 OK / 0 objects) [request=0.2098s mapping=0.0011s total=0.2112s]
重启应用后,restkit 会再次正确映射对象:
2015-01-27 10:33:13.918 <APP_NAME>[80400:12458200] I restkit.network:RKObjectRequestOperation.m:220 GET '<api url>' (200 OK / 1 objects) [request=0.3969s mapping=0.0332s total=0.4305s]
据我所知,我正在重置和取消相关的托管对象上下文和获取的结果控制器:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// These are lazily instantiated, so will be
// recreated the next time they are referenced
_fetchedResultsController = nil;
_managedObjectContext = nil;
}
我错过了什么?
更多信息 - 使用跟踪日志记录级别,我可以看到服务器正在正确返回数据,但它没有被映射。 (出于安全原因,数据被截断):
2015-01-27 17:32:03.773 <APP_NAME>[86020:12883038] T restkit.network:RKObjectRequestOperation.m:218 GET '<api url>' (200 OK / 0 objects) [request=0.3788s mapping=0.0011s total=0.3802s]:
response.headers={
Connection = "keep-alive";
"Content-Length" = 342;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 27 Jan 2015 16:32:03 GMT";
Etag = "\"-968344033\"";
Vary = "Accept-Encoding";
"X-Powered-By" = Express;
}
response.body={
"status": "success",
"data": { <--- truncated exactly one object --> }
}
另一个编辑: 该问题似乎只影响(正如预期的那样)实体映射,而不影响普通对象映射(在登录步骤中有一个这样的成功映射)。
【问题讨论】:
-
所以你清除了各种东西到零,但你什么时候重新创建它们?
-
好问题!我应该对此更准确。暂时更新问题。
标签: objective-c core-data restkit