Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:18:09+00:00 2026-06-12T00:18:09+00:00

I currently have an ap that attempts to open a webview based on certain

  • 0

I currently have an ap that attempts to open a webview based on certain servers I am communicating with.

However, I allow the user the capability to type in their own server IPs in case both the iphone/ipad and server(or other device) are not on the same network. However, I am attempting to use NSURLConnection to detect if I can open a connection with the given IP however NSURLConnection never returns an error, even if the server address(or even a random web address) is completely bogus.

the .h

        @interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDataSource, UITableViewDelegate,UIWebViewDelegate, NSURLConnectionDataDelegate> {

the relevant code in the .m

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
         (NSIndexPath *)indexPath
       {
        dev_ip = @"http://www.asdfasfdfa.com/";
        //dev_ip = (random ip)
        NSMutableURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:dev_ip]];

        NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        if (conn) {
            NSLog(@"Connection established");    

        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"No Device at designated IP"]

                                                           delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
      }

this if/else always outputs ‘Connection established.’ Is this something NSURLConnection should not be used for? If so, what can I use to detect devices at given IP’s for connectivity. I need to stop the user from attempting to connect to bad IP’s so whats the best method in doing so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:18:11+00:00Added an answer on June 12, 2026 at 12:18 am

    NSURLConnection, when used with delegation, will call delegate methods when it connects, fails to connect and receive data. You should look into NSURLConnectionDelegate.

    Here’s a quick example:

        // In your .h
    
        @interface MyClass : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate>
    
        @end
    

    EDIT You actually need both delegates.


        // In your .m
    
        @implementation MyClass
    
        - (void)myMethodToConnect {
    
             NSString *dev_ip = @"http://74.125.137.101"; // Google.com
    
             NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:dev_ip]];
    
             NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        }
    
        - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    
            switch ([(NSHTTPURLResponse *)response statusCode]) { // Edited this!
                case 200: {
                    NSLog(@"Received connection response!");
                    break;
                }
                default: {
                    NSLog(@"Something bad happened!");
                    break;
                }
            }
    
        }
    
        - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
            NSLog(@"Error connecting. Error: %@", error);
        }
        @end
    

    Also, just throwing it out there too, you don’t necessarily have to use an asynchronous call. You can send a synchronous call which doesn’t require you to implement a delegate. Here’s how:

        NSString *dev_ip = @"http://www.asdfasdfasdf.com/";
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:dev_ip]];
        NSURLResponse *response = nil;
        NSError *error = nil;
    
        NSData *connectionData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    

    You can check the response value and errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have form that checks if a user has unsubmitted changes when they
I currently have a function that will create X tasks of a function based
I currently have code that does the following: private final static ExecutorService pool =
I currently have one project that currently contains multiple packages. These packages make up
I currently have a label that is absolute positioned within a textarea. I'm trying
I currently have a variable that looks like this: val someVal = new HashMap[Float,
I currently have a script that deletes old log files and then takes any
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
We currently have a View that queries active directory info. I was wondering if
I currently have a website that I am trying to optimize in terms of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.