Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prepare an NSURL from an NSString continaing international characters?

I have to access a web server using a GET with international characters (Hebrew in my case but could be anything). So I make an NSString just fine but

[NSURL URLWithString:urlString]; // returns nil.

I realize I probably have to convert the international characters to percent codes.

Is there a built in method in Objective-c to do so?

like image 347
jkally Avatar asked Aug 05 '10 20:08

jkally


1 Answers

Yes there is, you need -stringByAddingPercentEscapesUsingEncoding: method:

[NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
like image 150
Vladimir Avatar answered Oct 14 '22 11:10

Vladimir