Objective c RestKit:注销时重置持久存储后映射的0个对象
在RestKit版本0.23.x上,我尝试在用户注销时重置core数据的持久存储,方法如下:Objective c RestKit:注销时重置持久存储后映射的0个对象,objective-c,core-data,restkit,Objective C,Core Data,Restkit,在RestKit版本0.23.x上,我尝试在用户注销时重置core数据的持久存储,方法如下: // Cancel all requests [[RKObjectManager sharedManager] cancelAllObjectRequestOperationsWithMethod:RKRequestMethodAny matchingPathPattern:@"/"]; [[RKObjectManager sharedManager].operationQueue cancelAll
// 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]
我错过了什么
更多信息-通过跟踪日志记录级别,我可以看到服务器正确地返回数据,但它没有被映射。出于安全原因,数据被截断:
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 --> }
}
另一编辑:
这个问题似乎只影响实体映射,而不是普通对象映射。登录步骤中有一个这样成功的映射。看起来我把问题复杂化了。现在有一个解决方案适合我:
// 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];
// Reset persistent stores
[self.managedObjectStore resetPersistentStores:nil];
澄清一下:根本不需要将任何东西归零。所以你将各种事情归零,但你什么时候重新创建它们呢?好问题!我应该更准确地说。暂时更新问题。之后是否仍设置所有RestKit值?我有相同的代码,但RestKit告诉我无法保存新登录用户的数据时出错:无法将托管对象上下文保存到持久存储。
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 --> }
}
// 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];
// Reset persistent stores
[self.managedObjectStore resetPersistentStores:nil];