ios webview url null problem

when i was trying to load a url in the uiWebView, my NSURL object is always nil when i init it this way:

NSURL *url = [[NSURL alloc] initWithString: urlString];

This is because:

If the string was malformed, returns nil.

This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.


So I have to init it as follows:

NSURL *url = [[NSURL alloc] initWithString: [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s