2013-07-04 23 views
1

我只是使用restkit patchobject更新内容。当第一次调用方法调用时会导致success.but在第二次调用同一方法时,应用程序崩溃与NSInternal不一致错误。不能为同一个class.thanks添加adddescriptor。下面的链接也有同样的问题,但我不知道如何解决。无法为同一类restkit添加请求描述符ios抛出错误nsinternal不一致性错误

Restkit + Objective-c - Multiple calls to same web service

这里是我的方法的代码

-(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"); 
}]; 

} 

回答

1

您面临的问题是因为您多次添加相同的请求描述符。例如,您应该只在应用程序委托中设置所有请求和响应描述符。

+ (void)setupDescriptors { 
    RKObjectManager *objectManager = [[AppDelegate appDelegate] objectManager]; 
    objectManager.requestSerializationMIMEType = RKMIMETypeJSON; 
    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); 
    // Add Request Descriptors 
    // 

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[Human rkEntityMappingForResponse:YES] method:RKRequestMethodAny pathPattern:nil keyPath:@"human" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

    RKRequestDescriptor *userRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[User rkObjectMappingForRequest:YES] objectClass:[User class] rootKeyPath:@"user" method:RKRequestMethodAny]; 
    RKRequestDescriptor *signupUserRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[User rkObjectMappingForSignupRequest:YES] objectClass:[User class] rootKeyPath:@"user" method:RKRequestMethodAny]; 


    [objectManager addRequestDescriptorsFromArray:@[signupUserRequestDescriptor,userRequestDescriptor]]; 

    RKResponseDescriptor *userResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[User rkEntityMappingForResponse:YES] method:RKRequestMethodAny pathPattern:nil keyPath:@"user" statusCodes:statusCodes]; 


    [objectManager addResponseDescriptorsFromArray:@[userResponseDescriptor,responseDescriptor]]; 
} 

但在某些情况下,你仍然要通过REST套件的作者作为回答添加多个请求描述那么这是由动态映射完成。请参阅以下链接。

Adding two request descriptors for a given class in Restkit 0.2

我希望这有助于。

0

不能为同一个键添加一个描述符的两倍。你还没有添加任何代码,但我知道你正在调用'patch'的方法中添加所有的映射和​​描述符。不要...

将您的配置与您的使用分开。将所有映射和描述符设置代码放入一个方法中,并在做其他任何操作之前调用它。然后,当你想'补丁'时,调用一个不同的方法,只是这样做,并不包含任何额外的映射。