开发者

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

开发者 https://www.devze.com 2023-03-31 19:57 出处:网络
When I 开发者_StackOverflow中文版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...

When I 开发者_StackOverflow中文版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?


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!
}


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消