在使用loadObjectsAtResourcePath执行GET时,我能够获取所有必需的RKObjectLoaderDelegate方法:delegate:。
但是,当我使用post:params:delegate:进行POST时,只有request:didLoadResponse:被调用。甚至没有调用objectLoader:didLoadObjects:和objectLoader:didFailWithError:等方法。
以下是代码段。
self.appObjectManager.client = [RKObjectManager managerWithBaseURLString:self.webServiceURLString];
[self.appObjectManager.client setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[self.appObjectManager.client setValue:@"" forHTTPHeaderField:@"Cookie"];
RKObjectMapping* sessionInformationMapping = [RKObjectMapping mappingForClass:[sessionInformation class]];
[sessionInformationMapping mapKeyPath:@"uid" toAttribute:@"userID"];
[self.appObjectManager.mappingProvider setObjectMapping:sessionInformationMapping forKeyPath:@"user"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"abc", @"pwd", nil]
forKeys:[NSArray arrayWithObjects:@"username", @"password", nil]];
[self.appObjectManager.client post:resourcePath params:parameters delegate:self];
我在这里发现了类似的问题,但它似乎对我没有帮助。 RestKit: What delegate method is called for postObject?
答案 0 :(得分:0)
试试这个而不是post:params:delegate:
[self.appObjectManager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader * loader) {
loader.method = RKRequestMethodPOST;
loader.params = params;
loader.delegate = self;
}];
当响应返回时,应调用objectLoader委托方法。