ios - How to make NSURL with special characters -


my application based in portuguese - brazil. have special characters use in words "açaí".

i have search method sends request url this:

 nsurlsession *session = [nsurlsession sharedsession];     nsstring *urlstring = [nsstring stringwithformat:@"http://www.mydomain.com.br/webservice/search/%@",_query];     nsurl *url = [nsurl urlwithstring:urlstring];     [[session datataskwithurl:url             completionhandler:^(nsdata *data,                                 nsurlresponse *response,                                 nserror *error) {    //all logic here                 });              }] resume]; 

now, if _query set "açaí" (which has ç , í special characters) when try nsurl *url = [nsurl urlwithstring:urlstring]; url variable not initialized , breaks rest.

how can send request web service using special characters?

i think need escape url string before creating nsurl.

nsstring *urlstring = [nsstring stringwithformat:@"http://www.mydomain.com.br/webservice/search/%@",_query]; nsurl *url = [nsurl urlwithstring:[urlstring stringbyaddingpercentescapesusingencoding: nsutf8stringencoding]]; 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -