Я пытаюсь иметь вертикальные каналы в URL-адресе
Входная строка: http://testURL.com/Control?command=dispatch|HOME|ABC:User
-(NSString *)getURLEncodedString:(NSString *)stringvalue{
NSMutableString *output = [NSMutableString string];
const unsigned char *source = (const unsigned char *)[stringvalue UTF8String];
int sourceLen = strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
const unsigned char thisChar = source[i];
if (thisChar == ':' || thisChar == '/' || thisChar == '?' || thisChar == '=' || thisChar == '|' || thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
(thisChar >= 'A' && thisChar <= 'Z') ||
(thisChar >= '0' && thisChar <= '9')) {
[output appendFormat:@"%c", thisChar];
} else {
[output appendFormat:@"%%%02X", thisChar];
}
}
return output;
}
Выходная строка после вызова вышеуказанного метода: http://testURL.com/Control?command=dispatch|HOME|ABC:User%20Name
Теперь, если я передам приведенную выше строку кодирования в [[NSURL URLWithString:encodedString];
Я получаю Domain=NSURLErrorDomain Code=-1000 "неверный URL" UserInfo=0xae9d760 {NSUnderlyingError=0xaec8ed0 "неверный URL", NSLocalizedDescription=плохой URL}
Любые данные об этом, ребята? Я хочу, чтобы URL-адрес выглядел как encodedString.
Спасибо!