user549211
user549211

Reputation: 209

How to access internet on iPhone simulator?

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.

Upvotes: 4

Views: 10262

Answers (4)

gabaum10
gabaum10

Reputation: 3827

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.

Upvotes: 1

Riccardo Moschetti
Riccardo Moschetti

Reputation: 181

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.

Upvotes: 1

Veeru
Veeru

Reputation: 4936

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.

Upvotes: 3

stackr
stackr

Reputation: 2742

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

Upvotes: 10

Related Questions