我只是使用restkit patchobject 更新内容。当第一次调用方法调用时,它会导致成功。但是在第二次调用相同的方法时,应用程序崩溃并出现NSInternal 不一致错误。无法为同一类添加adddescriptor。谢谢。下面的链接也有同样的问题,但我不知道如何解决。
Restkit + Objective-c - 多次调用同一个 Web 服务
这是我的方法代码
-(void)setContact:(int)_orgID :(int)_personID :(Person *)p1
{
AddressScreenViewController *addressView= [[AddressScreenViewController alloc]init];
addressView.mobileno = p1.mobile_phone;
addressView.workno = p1.work_phone;
addressView.homeno = p1.home_phone;
addressView.address1=p1.address1;
addressView.address2=p1.address2;
addressView.city=p1.city;
addressView.zip=p1.zip;
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
LoginAppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
RKObjectManager *objectManager = [RKObjectManager sharedManager];
[objectManager setRequestSerializationMIMEType:RKMIMETypeJSON];
RKObjectMapping *personRequestMapping = [RKObjectMapping requestMapping];
[personRequestMapping addAttributeMappingsFromDictionary:@{ @"mobileno" : @"phone_numbers.mobile_number", @"workno" : @ "phone_numbers.work_number" , @"homeno" :@"phone_numbers.home_number",@"address1":@"mailing_address.address1",@"address2":@"mailing_address.address2",@"city":@"mailing_address.city",@"zip":@"mailing_address.zip"}];
RKLogConfigureByName("RestKit", RKLogLevelWarning);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKRequestDescriptor *requestDescriptor =[RKRequestDescriptor requestDescriptorWithMapping:personRequestMapping objectClass:[AddressScreenViewController class] rootKeyPath:@"person"];
[objectManager addRequestDescriptor:requestDescriptor];
NSString * orgPath = [NSString stringWithFormat:myurl];
[objectManager patchObject:addressView path:orgPath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result)
{
NSLog(@"result: %@", result);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"failuer function");
}];
}