2012-05-11 2 views
2

У меня проблема с RestKitRKObjectLoader trunc my path с параметрами массива

Я пытаюсь отправить в строку строки параметров. Делать это так.

RKObjectMapping* tagMapping = [[RKObjectManager sharedManager].mappingProvider 
    objectMappingForClass:[RKTag class]]; 
NSArray *tags = [NSArray arrayWithObjects:@"Home", @"Relation", nil]; 
NSDictionary *dictParams = 
    [NSDictionary dictionaryWithObject:tags forKey:@"type"]; 

NSString *resourcePath = [[NSString stringWithString:@"/tags"] 
    stringByAppendingQueryParameters:dictParams]; 
[_m loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) { 
    [loader setObjectMapping:tagMapping]; 
    [loader setMethod:RKRequestMethodGET]; 
    [loader setDelegate:delegate]; 
}]; 

Но, когда я вижу консоль на сервере, я вижу

Started GET «/ теги? Тип% 5B% 5D =% D0% A0% D0% BE% D0% B4% D1 % 81% D1% 82% D0% B2% D0% B5% D0% BD% D0% BD% D1% 8B% D0% B5% 20% D0% BE% D1% 82% D0% BD% D0% BE% D1 % 88% D0% B5% D0% BD% D0% B8% D1% 8F "для 127.0.0.1 в 2012-05-11 16:30:54 +0400 Обработка тегамиController # index as JSON Параметры: {" type "=> [" Главная "]}

при инициализации RKObjectLoader, метод вызова l oaderWithResourcePath, что усекает мой массив

Как это исправить?

ответ

0

я могу решить эту проблему путем изменения RKUrlClass

- (id)initWithBaseURL:(NSURL *)theBaseURL resourcePath:(NSString *)theResourcePath queryParameters:(NSDictionary *)theQueryParameters { 
    NSDictionary *resourcePathQueryParameters = [theResourcePath queryParameters]; 
    NSMutableDictionary *mergedQueryParameters = [NSMutableDictionary dictionaryWithDictionary:[theBaseURL queryParameters]]; 
    [mergedQueryParameters addEntriesFromDictionary:resourcePathQueryParameters]; 
    [mergedQueryParameters addEntriesFromDictionary:theQueryParameters]; 

    // Build the new URL path 
    NSRange queryCharacterRange = [theResourcePath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"?"]]; 
    NSString *resourcePathWithoutQueryString = (queryCharacterRange.location == NSNotFound) ? theResourcePath : [theResourcePath substringToIndex:queryCharacterRange.location]; 
    NSString *baseURLPath = [[theBaseURL path] isEqualToString:@"/"] ? @"" : [[theBaseURL path] stringByStandardizingPath]; 
    NSString *completePath = resourcePathWithoutQueryString ? [baseURLPath stringByAppendingString:resourcePathWithoutQueryString] : baseURLPath; 
    NSString* completePathWithQuery = [completePath stringByAppendingQueryParameters:mergedQueryParameters]; 

    // before 
    // NSURL* completeURL = [NSURL URLWithString:completePathWithQuery relativeToURL:theBaseURL]; 
    // after my edit 
    NSString *cPath = theResourcePath ? theResourcePath : baseURLPath; 
    NSURL* completeURL = [NSURL URLWithString:cPath relativeToURL:theBaseURL]; 

    if (!completeURL) { 
     RKLogError(@"Failed to build RKURL by appending resourcePath and query parameters '%@' to baseURL '%@'", theResourcePath, theBaseURL); 
     [self release]; 
     return nil; 
    } 

    self = [self initWithString:[completeURL absoluteString]]; 
    if (self) { 
     self.baseURL = theBaseURL; 
     self.resourcePath = theResourcePath; 
    } 

    return self; 
} 
Смежные вопросы