2017-04-13 4 views
0

URL을 작성하고 경로의 모든 특수 문자가 인코딩되도록 노력하고 있습니다. 현재는이를 수행하지 않았습니다. path 속성이 NSURLComponents 인 방법에 대한 오해로 인한 것일 수 있습니다. 공장. URLPathAllowedCharacterSet이 느낌표를 인코딩하지 않음

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; 

NSURLQueryItem *queryItem = [NSURLQueryItem queryItemWithName: @"queryName" value: @"queryValue"]; 
components.queryItems = @[queryItem]; 

는 // 나는 stringByAddingPercentEncodingWithAllowedCharacters 같은 문자를 인코딩 것이라고 생각했다 "!" "% 21"으로

components.path = [components.path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; 

[items addObject:components.URL]; 

내가 components.path 근본적으로 뭔가 잘못하고 있는가 인코딩되지 않은,와! ""URL을 돌려줍니다 //?

도움을 주신 모든 분들께 미리 감사드립니다.

답변

1

URLPathAllowedCharacterSet의 변경 가능한 복사본을 만들고 "!"을 제거하여 새 문자 집합을 만듭니다.

NSMutableCharacterSet *characterSet = [[NSCharacterSet URLPathAllowedCharacterSet] mutableCopy]; 
[characterSet removeCharactersInString:@"!"]; 
1

URLPathAllowedCharacterSet 포함하지 "!", 따라서 당신은 사용이 세트를 열거 할 수

인코딩되지 않습니다이 루틴 URLPathAllowedCharacterSet가 포함되어 있기 때문에 "!", 당신은을 만들어야합니다

NSCharacterSet *set = [NSCharacterSet URLPathAllowedCharacterSet]; 

    for (int plane = 0; plane <= 16; plane++) { 
     if ([set hasMemberInPlane:plane]) { 
      UTF32Char c; 
      for (c = plane << 16; c < (plane+1) << 16; c++) { 
       if ([set longCharacterIsMember:c]) { 
        UTF32Char c1 = OSSwapHostToLittleInt32(c); // To make it byte-order safe 
        NSString *s = [[NSString alloc] initWithBytes:&c1 length:4 encoding:NSUTF32LittleEndianStringEncoding]; 
        NSLog(@"%@", s); 
       } 
      } 
     } 
    }