问题描述
我有一个动物列表和特殊按钮.当我按下按钮时,我想去维基百科阅读更多关于这种动物的信息.所以我写了这段代码:
I have an animal list and special button. When I press the button, I would like to go to Wikipedia and read about this animal more. So I wrote this code:
-(IBAction)goWiki:(id)sender
{
NSString *wikiUrl = "http://ru.wikipedia.org/wiki/";
NSString *url = [NSString stringWithFormat:@"%@%@",wikiUrl,animalTitle];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
NSLog(@"%@",url);
}
NSLog
显示 url 写入正确,但是没有任何反应.我 99.9% 肯定是因为 animalTitle
.我的母语是俄语,animalTitle
也是俄语中的动物名称.因此,如果链接类似于 http://ru.wikipedia.org/wiki/Frog,它可以正常工作,但如果它像http://ru.wikipedia.org/wiki/Лягушка 没有任何反应.任何想法,我怎样才能转到俄语文章?谢谢!
NSLog
shows that url was written correctly, however, nothing happened. I am 99,9% sure its because of animalTitle
. My native language is russian and animalTitle
is also an animal name in russian.So if link is like http://ru.wikipedia.org/wiki/Frog its fine and it works but if its likehttp://ru.wikipedia.org/wiki/Лягушка nothing happens.Any ideas, how can I move to a russian article?Thanks!
推荐答案
使用 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
如下 -
-(IBAction)goWiki:(id)sender
{
NSString *wikiUrl = @"http://ru.wikipedia.org/wiki/";
NSString *url = [NSString stringWithFormat:@"%@%@",wikiUrl,animalTitle];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
NSLog(@"%@",url);
}
这篇关于Xcode openURL 不读取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!