調用Web服務,我試圖調用Web服務,並上傳圖片,錯誤而與restkit API目標C
有在映射出了問題,我已經在上面花了很多時間都沒有成功。我得到的錯誤是:
錯誤域= org.restkit.RestKit.ErrorDomain代碼= 1001「被發現在關鍵路徑沒有可映射 對象表示搜查。」 。 的UserInfo = {NSLocalizedDescription =否可映射對象表示 在鍵路徑被發現搜索,NSLocalizedFailureReason =該 映射操作是無法找到任何嵌套對象在鍵路徑申述 搜尋:用戶輸入到 映射器的表示被發現含有在 以下關鍵路徑嵌套的對象表示:信息,成功這可能表明你 已經配置錯誤的關鍵路徑,您的映射,的keyPath = NULL, DetailedErrors =()}
,並在那裏。方法調用web服務
[SVProgressHUD show];
[delegate.objectManager.HTTPClient.defaultHeaders setValue:@"application/x-www-form-urlencoded" forKey:@"content-type" ];
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[SignUpResponse class]]; //create response and request mapping
[responseMapping addAttributeMappingsFromDictionary:@{@"phone": @"phone",
@"device_type": @"device_type",
@"device_token": @"device_token",
@"type": @"type",
@"email": @"email",
@"identity": @"identity",
@"date": @"date",
@"status": @"status",
@"name": @"name",
@"activation": @"activation",
@"image": @"image",
@"id": @"id"
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
method:RKRequestMethodPOST
pathPattern:@"AgentRegister"
keyPath:@"user"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[delegate.objectManager.defaultHeaders setValue:@"application/x-www-form-urlencoded" forKey:@"content-type" ];
delegate.objectManager.requestSerializationMIMEType =RKMIMETypeFormURLEncoded;
[delegate.objectManager removeResponseDescriptor:responseDescriptor];
[delegate.objectManager addResponseDescriptor:responseDescriptor];
NSString *fcmToken = [FIRInstanceID instanceID].token;
SignUpRequest *signUpRequest = [[SignUpRequest alloc]init];
signUpRequest.phone = txtPhoneNumber.text;
signUpRequest.email = txtEmail.text;
signUpRequest.identity=txtIdOrCity.text;
[email protected]"IOS";
signUpRequest.device_token=fcmToken;
[email protected]"1";
UIImage *image = [UIImage imageNamed:@"Logo"];
// Serialize the Article attributes then attach a file
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:signUpRequest method:RKRequestMethodPOST path:@"AgentRegister" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(image)
name:@"image"
fileName:@"photo.png"
mimeType:@"application/x-www-form-urlencoded"];
}];
RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
[SVProgressHUD dismiss];
if(mappingResult.array.count !=0){
[self performSegueWithIdentifier:@"goToVerify" sender:self];
}else{
}
[delegate.objectManager removeResponseDescriptor:responseDescriptor];
}failure:^(RKObjectRequestOperation *operation, NSError *error){
[SVProgressHUD dismiss];
NSLog(@"%@",error.description);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@".."
message:@"حدث خطاء ما .. حاول مرة اخري" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
[delegate.objectManager removeResponseDescriptor:responseDescriptor];
}];
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation];
}