How to access internet on iPhone simulator?

10,124

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
10,124
user549211
Author by

user549211

Updated on June 04, 2022

Comments

  • user549211
    user549211 almost 2 years

    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.