iPhone Dev

url encoding

떡공이 2014. 6. 3. 10:29

iOS7 이상

NSString *unescaped = @"http://www";

NSString *charactersToEscape = @"!*'();:@&=+$,/?%#[]\" ";

NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];

NSString *encodedString = [unescaped stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];


iOS7 이하

NSString *escapedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(

    NULL,

   (__bridge CFStringRef) unescaped,

    NULL,

    CFSTR("!*'();:@&=+$,/?%#[]\" "),

    kCFStringEncodingUTF8));