xcode 如何在 iPhone 模拟器上访问互联网?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4603767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access internet on iPhone simulator?
提问by user549211
I would like to access internet on iPhone simulator in xcode. I would like to test some urls in my code.
我想在 xcode 中的 iPhone 模拟器上访问互联网。我想在我的代码中测试一些网址。
How is it possible?
这怎么可能?
Thanks you.
谢谢。
回答by stackr
If you have connection to internet on the development machine the simulator uses that.. There are no special things you have to do.. just make sure you are connected to the internet with your mac
如果您在开发机器上连接到互联网,模拟器就会使用它.. 没有什么特别的事情你需要做.. 只需确保你的 mac 连接到互联网
回答by Veeru
if what you are asking is to test internet connectivity - you can use the Reachability class, which is available all over the internet. It can tell you if the internet/url is available or not.
如果您要测试互联网连接 - 您可以使用 Reachability 类,该类可在整个互联网上使用。它可以告诉您互联网/网址是否可用。
回答by gabaum10
Do you mean,
你的意思是,
"How do I launch a URL in Safari from my code?". If that is the case, do something like this:
“如何从我的代码在 Safari 中启动 URL?”。如果是这种情况,请执行以下操作:
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
Hope that helps.
希望有帮助。
回答by Riccardo Moschetti
Do not forget that URLs for web pages have to begin with the "http://" or "https://" protocol indicator.
不要忘记网页的 URL 必须以“http://”或“https://”协议指示符开头。
That's why the code
这就是为什么代码
NSURL *url = [NSURL URLWithString:@"www.google.com/"]
NSURL *url = [NSURL URLWithString:@"www.google.com/"]
will not open Safari in the iOS simulator, whereas the
不会在 iOS 模拟器中打开 Safari,而
NSURL *url = [NSURL URLWithString:@"HTTP://www.google.com/"]
NSURL *url = [NSURL URLWithString:@"HTTP://www.google.com/"]
will.
将要。