Xcode openURL 无法读取链接
我有一个动物列表和特殊按钮。当我按下按钮时,我想访问维基百科并了解有关这种动物的更多信息。所以我写了这段代码:
-(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/Лягушка没有任何反应。 有什么想法吗,我怎样才能转到俄语文章? 谢谢!
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
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 like
http://ru.wikipedia.org/wiki/Лягушка nothing happens.
Any ideas, how can I move to a russian article?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
如下 -use
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
as follows -首先尝试通过 CFURLCreateStringByAddingPercentEscapes 传递字符串
animalTitle
。Try passing the string
animalTitle
through CFURLCreateStringByAddingPercentEscapes first.