4

我在 RestKit 的错误回调中切换控制器时遇到问题。它会导致错误:

*** -[RKObjectLoader onDidFailWithError]: message sent to deallocated instance 0x1ddd9680

我正在- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error使用以下代码切换方法:

[[[[RKObjectManager sharedManager] client] requestQueue] cancelAllRequests];

scAppDelegate *appDelegate = (scAppDelegate *)[UIApplication sharedApplication].delegate;
WelcomeController *controller = [[WelcomeController alloc] init];
[controller createWelcome];
appDelegate.window.rootViewController = controller;
[appDelegate.window addSubview:[controller view]];
[appDelegate.window makeKeyAndVisible];

我的问题在第一行,因为它不会取消所有 RestKit 处理。在日志中,我看到了一些 ObjectMapping 操作,它们导致了EXC_BAD_ACCESS (SIGSEGV)错误。我找到了一种解决方法 - 延迟后切换控制器(使用performSelector:withObject:afterDelay)。但我正在寻找更好的解决方案。

ObjectMapping 操作是:

2012-09-26 14:50:09.408 dr[5004:907] W restkit.object_mapping:RKObjectMapper.m:87 Adding mapping error: Could not find an object mapping for keyPath: ''
2012-09-26 14:50:09.410 dr[5004:907] E restkit.network:RKObjectLoader.m:231 Encountered errors during mapping: Could not find an object mapping for keyPath: ''
2012-09-26 14:50:09.411 dr[5004:907] E restkit.network:RKObjectLoader.m:360 Encountered an error while attempting to map server side errors from payload: Could not find an object mapping for keyPath: ''
2012-09-26 14:50:09.419 dr[5004:907] I restkit.support:RKCache.m:189 Invalidating cache at path: /var/mobile/Applications/1B9919DC-0674-494D-9C26-F1FC1925E856/Library/Caches/RKClientRequestCache-dr.cloudapp.net/SessionStore
2012-09-26 14:50:09.422 dr[5004:907] I restkit.network.reachability:RKReachabilityObserver.m:123 Reachability observer initialized with IP address: 0.0.0.0.

我正在使用最新版本的 RestKit。

4

2 回答 2

1

从 RestKit 0.20.0 开始:

[[[RKObjectManager sharedManager] operationQueue] cancelAllOperations];
于 2014-10-23T19:45:41.547 回答
0

您是否有理由要求客户取消所有操作?通常你会要求 RKObjectManager 来完成这项工作。

[[[[RKObjectManager sharedManager] requestQueue] cancelAllRequests];
于 2012-11-25T10:31:58.463 回答