簡體   English   中英

RKMappingresult在帶有Restkit的64位iPhone中返回不同的結果

[英]RKMappingresult returning different result in 64-bit iphones with restkit

Restkit我有一個奇怪的問題。 我正在執行以下操作:

-(void)doLogin:(NSString *)email andPassword:(NSString *)password OnCompletion:(myCompletion) compblock{
    Mapper *mapper = [Mapper new];
    RKManagedObjectStore *store = [[OffitelDataModel sharedDataModel] objectStore];
    NSLog(@"store is %@",store);
    NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
    RKObjectManager *objectManager = [mapper mapLogin];
    NSString *deviceToken = [[NSUserDefaults standardUserDefaults]objectForKey:@"deviceToken"];
    NSString *urlString = [NSString stringWithFormat:@"company-user/login/%@?email=%@&pwd=%@&ios_id=%@",apikey,email,password,deviceToken];
    NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil];
    RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSError *error = nil;
        BOOL success = [context  save:&error];
        if (!success) RKLogWarning(@"Failed saving managed object context: %@", error);
        Data *data2 = [mappingResult.array objectAtIndex:0];
        NSLog(@"MAPPING RESULT 0 = %@",[mappingResult.array objectAtIndex:0]);
        NSLog(@"data status is %@",data2.webstatus);
        int value = [data2.webstatus intValue];
        if (value == 200){
            Person  *personObject = [mappingResult.array objectAtIndex:2];
            NSString *name = [NSString stringWithFormat:@"%@ %@",personObject.cu_first_name,personObject.cu_last_name];
            NSDictionary *dictUser = [[NSDictionary alloc]initWithObjectsAndKeys:personObject.cu_id,@"personId",personObject.company.c_id,@"companyId",name,@"personName",personObject.cu_status_id,@"statusId", nil];
            [[NSUserDefaults standardUserDefaults]setObject:dictUser forKey:@"user"];
            [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:@"loggedIn"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            compblock(YES);
        }else{
            //show validation
            NSLog(@"ERROR");
        }
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
         NSLog(@"ERROR");
    }];
    [objectManager enqueueObjectRequestOperation:operation];
}

恩這是我的映射

-(RKObjectManager *)mapLogin{

    RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[Data class]];
    [dataMapping addAttributeMappingsFromDictionary:@{
                                                      @"status": @"webstatus",
                                                      @"message": @"message",
                                                      @"text": @"text"
                                                      }];
    RKEntityMapping* personMapping = [RKEntityMapping mappingForEntityForName:@"Person" inManagedObjectStore:managedObjectStore];
    personMapping.identificationAttributes = @[@"cu_id"] ;
    [personMapping addAttributeMappingsFromDictionary:@{
                                                        @"cu_id":              @"cu_id",
                                                        @"cu_status_id":       @"cu_status_id",
                                                        @"cu_company_id":      @"cu_company_id",
                                                        @"cu_function_id":     @"cu_function_id",
                                                        @"cu_department_id":   @"cu_department_id",
                                                        @"cu_email":           @"cu_email",
                                                        @"cu_first_name":      @"cu_first_name",
                                                        @"cu_last_name":       @"cu_last_name",
                                                        @"cu_phone_intern":    @"cu_phone_intern",
                                                        @"cu_mobile_phone":    @"cu_mobile_phone",
                                                        @"cu_street":          @"cu_street",
                                                        @"cu_number":          @"cu_number",
                                                        @"cu_bus":             @"cu_bus",
                                                        @"cu_postalcode":      @"cu_postalcode",
                                                        @"cu_location":        @"cu_location",
                                                        @"cu_country":         @"cu_country",
                                                        @"cu_birthdate":       @"cu_birthdate",
                                                        @"cu_picture":         @"cu_picture",
                                                        @"cu_comment":         @"cu_comment",
                                                        @"cu_ison_reminder_email": @"cu_ison_reminder_email",
                                                        @"cu_ison_reminder_app":   @"cu_ison_reminder_app",
                                                        @"cu_ison_reminder_web":   @"cu_ison_reminder_web",
                                                        @"cu_first_use":       @"cu_first_use"
                                                        }];
    RKEntityMapping* functionMapping = [RKEntityMapping mappingForEntityForName:@"Function" inManagedObjectStore:managedObjectStore];
    functionMapping.identificationAttributes = @[@"cf_id"] ;
    [functionMapping addAttributeMappingsFromDictionary:@{
                                                          @"cf_id": @"cf_id",
                                                          @"cf_name":@"cf_name"
                                                          }];
    RKEntityMapping* departmentMapping = [RKEntityMapping mappingForEntityForName:@"Department" inManagedObjectStore:managedObjectStore];
    departmentMapping.identificationAttributes = @[@"cd_id"] ;
    [departmentMapping addAttributeMappingsFromDictionary:@{
                                                            @"cd_id": @"cd_id",
                                                            @"cd_name":@"cd_name"
                                                            }];
    RKEntityMapping* companyMapping = [RKEntityMapping mappingForEntityForName:@"Company" inManagedObjectStore:managedObjectStore];
    companyMapping.identificationAttributes = @[@"c_id"] ;
    [companyMapping addAttributeMappingsFromDictionary:@{
                                                         @"c_id": @"c_id",
                                                         @"c_name":@"c_name",
                                                         @"c_phone":@"c_phone",
                                                         @"c_fax":@"c_fax",
                                                         @"c_website":@"c_website"
                                                         }];

    RKEntityMapping* statusMapping = [RKEntityMapping mappingForEntityForName:@"Status" inManagedObjectStore:managedObjectStore];
    statusMapping.identificationAttributes = @[@"cs_id"] ;
    [statusMapping addAttributeMappingsFromDictionary:@{
                                                        @"cs_id": @"cs_id",
                                                        @"cs_company_id":@"cs_company_id",
                                                        @"cs_name":@"cs_name",
                                                        @"cs_default":@"cs_default",
                                                        @"cs_image":@"cs_image"
                                                        }];
    RKRelationshipMapping* relationFunctionMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"function"toKeyPath:@"function"withMapping:functionMapping];
    RKRelationshipMapping* relationDepartmentMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"department"toKeyPath:@"department"withMapping:departmentMapping];
    RKRelationshipMapping* relationCompanyMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"company"toKeyPath:@"company"withMapping:companyMapping];
    RKRelationshipMapping* relationStatusMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"statuses"toKeyPath:@"status"withMapping:statusMapping];

    [personMapping addPropertyMapping:relationFunctionMapping];
    [personMapping addPropertyMapping:relationDepartmentMapping];
    [personMapping addPropertyMapping:relationCompanyMapping];
    [companyMapping addPropertyMapping:relationStatusMapping];
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping
                                                                                       pathPattern:nil
                                                                                           keyPath:@"data"                                                                                       statusCodes:[NSIndexSet indexSetWithIndex:200]];
    RKResponseDescriptor *responseDescriptor2 = [RKResponseDescriptor responseDescriptorWithMapping:personMapping
                                                                                        pathPattern:nil
                                                                                            keyPath:@"data.user"
                                                                                        statusCodes:[NSIndexSet indexSetWithIndex:200]];
    RKResponseDescriptor *responseDescriptor3 = [RKResponseDescriptor responseDescriptorWithMapping:companyMapping
                                                                                        pathPattern:nil
                                                                                            keyPath:@"data.user.company"
                                                                                        statusCodes:[NSIndexSet indexSetWithIndex:200]];
    NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor,responseDescriptor2,responseDescriptor3, nil];

    [objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
    return objectManager;
}

奇怪的是,在大多數手機上,它們都可以正常工作,但僅在64-bit devices上出了問題。

當我看這個NSLog

NSLog(@"MAPPING RESULT 0 = %@",[mappingResult.array objectAtIndex:0]);

我看到在not-64-bit devices它返回Data class對象。 沒關系。 但是,在64-bit devices它返回Company-object ,這不行!

有人可以幫我嗎?

親切的問候

您有多個響應描述符,每個描述符都有一個nil路徑模式,因此它們將始終應用於任何響應。 RestKit不保證將調用它們的順序。 它也不能保證mappingResult.array內容的順序。

您應該在響應描述符上使用關鍵路徑來訪問每個描述符的結果。 mappingResult還為您提供了一個字典(而不是數組),您可以在其中使用響應描述符鍵路徑來訪問關聯的結果。 使用它可以將Data結果與Company結果分開。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM