开发者

How to access internet on iPhone simulator?

开发者 https://www.devze.com 2023-02-02 20:08 出处:网络
I would lik开发者_StackOverflow中文版e to access internet on iPhone simulator in xcode. I would like to test some urls in my code.

I would lik开发者_StackOverflow中文版e to access internet on iPhone simulator in xcode. I would like to test some urls in my code.

How is it possible?

Thanks you.


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


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.


Do not forget that URLs for web pages have to begin with the "http://" or "https://" protocol indicator.

That's why the code

NSURL *url = [NSURL URLWithString:@"www.google.com/"]

will not open Safari in the iOS simulator, whereas the

NSURL *url = [NSURL URLWithString:@"HTTP://www.google.com/"]

will.


Do you mean,

"How do I launch a URL in Safari from my code?". If that is the case, do something like this:

NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
if (![[UIApplication sharedApplication] openURL:url])
    NSLog(@"%@%@",@"Failed to open url:",[url description]);

Hope that helps.

0

精彩评论

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