Replacement for stringByAddingPercentEscapesUsingEncoding in ios9?

后端 未结 8 1485
耶瑟儿~
耶瑟儿~ 2020-11-29 01:09

In iOS8 and prior I can use:

NSString *str = ...; // some URL
NSString *result = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


        
相关标签:
8条回答
  • 2020-11-29 01:36

    What is the meaning of "This method is intended to percent-encode an URL component or subcomponent string, NOT an entire URL string." ? – GeneCode Sep 1 '16 at 8:30

    It means that you are not supposed to encode the https://xpto.example.com/path/subpath of the url, but only what goes after the ?.

    Supposed, because there are use-cases for doing it in cases like:

    https://example.com?redirectme=xxxxx
    

    Where xxxxx is a fully encoded URL.

    0 讨论(0)
  • 2020-11-29 01:40

    Objective-C

    this code work for me :

    urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    
    0 讨论(0)
提交回复
热议问题