String won't url encode in iOS

后端 未结 1 456
礼貌的吻别
礼貌的吻别 2020-12-03 15:10

I\'m seriously having a brain fart here, but I can\'t figure out why this isn\'t encoding for the life of me. Been searching all over, and I can\'t even get

相关标签:
1条回答
  • 2020-12-03 16:09

    For future reference, this is what I found to work (i.e. encode everything properly)

    + (NSString*)encodeURL:(NSString *)string
    {
        NSString *newString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
    
        if (newString) 
        {
            return newString;
        }
    
        return @"";
    }
    
    0 讨论(0)
提交回复
热议问题