Re: Detecting Internet
Re: Detecting Internet
- Subject: Re: Detecting Internet
- From: Jerry Krinock <email@hidden>
- Date: Fri, 14 Jul 2006 17:01:17 -0700
- Thread-topic: Detecting Internet
on 06/07/14 14:06, Gerriet M. Denkmann at email@hidden wrote:
> On 14.07.2006, at 17:49, Jerry Krinock <email@hidden> wrote:
>> Create and load an NSURLConnection. If you're not connected to the
>> internet, you immediately get an NSURLResponse with a -1009 status
>> code.
>
> Just tried it.... [describes something different]
No, Garriet, you did not try what I said. Here is some code to get you
started:
NSURL* url = [NSURL urlWithString:@"http://www.apple.com"] ;
NSURLRequest* request=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:65536.0];
// since timeoutInterval is broken, I set it to a large value and
// use an "external" NSTimer to time out.
NSURLConnection* connection = [NSURLConnection
connectionWithRequest:mutableRequest delegate:self] ;
In the documentation for these methods you'll find a link to the "URL
Loading System" document which you should read. Short answer: After
executing the above code, your delegate will recieve one of two messages,
either -connection:didReceiveResponse: or -connect:didFailWithError:. If
you don't have an internet connection, you'll get the latter, within
milliseconds, and when you unpack the status code of that "error" (the
second argument), you'll find that it is -1009. Bingo. No internet
connection.
If you're not using that NSURLConnection for anything else, it's a kludge,
but it works.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden