mukesh
mukesh

Reputation: 1

uiwebview does not work if i change something in address bar?

When I type https://en.wikipedia.org/wiki/united_kingdom in webview address bar it works, but if type https://en.wikipedia.org/wiki/united kingdom it does not...

Can anyone explain to me why this is happening?

Upvotes: 0

Views: 270

Answers (2)

drexsien
drexsien

Reputation: 952

Browsers does not allow blanks spaces. Web Browser (desktop) like chrome, ie etc automatically convert blanks spaces to percent sign %. To do this on objective c you need to encapsulate it with stringByAddingPercentEscapesUsingEncoding method. Below is a working example.

NSString *myUrl = @"http://en.m.wikipedia.org/wiki/united kingdom";
[myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Upvotes: 0

JonasG
JonasG

Reputation: 9324

You cannot have spaces in a url, thats why its not working!

Edit: To avoid having spaces in your url, you can check if the url has got any spaces, and if, show an alert.

if([url.text rangeOfString:@" "].location != NSNotFound) {
    //url contains a space, show an alert and don't load the request here!
}
else {
    //load the request into your webview!
}

Upvotes: 1

Related Questions