4

I would like to access internet on iPhone simulator in xcode. I would like to test some urls in my code.

How is it possible?

Thanks you.

user549211
  • 179
  • 2
  • 5
  • 14
  • This is really vague. Do you mean you need to access them via an NSURLConnection? Do you want to launch safari? Please elaborate if you want any constructive help. – gabaum10 Jan 05 '11 at 21:13

4 Answers4

10

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

stackr
  • 2,742
  • 27
  • 44
  • 6
    This isn't true for me. I'm connected to the internet, but my simulator keeps popping up saying "Cannot connect to internet". Any other ideas? – Matt Huggins Jun 17 '14 at 16:59
3

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.

Veeru
  • 4,936
  • 2
  • 43
  • 61
1

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.

1

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.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
gabaum10
  • 3,769
  • 3
  • 48
  • 89