我有一个奇怪的问题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
,那是不行的!
有人可以帮我吗?
亲切的问候