FROM : Jerry Krinock
DATE : Sat Jul 15 02:01:17 2006
on 06/07/14 14:06, Gerriet M. Denkmann at <email_removed> wrote:
> On 14.07.2006, at 17:49, Jerry Krinock <<email_removed>> 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.
DATE : Sat Jul 15 02:01:17 2006
on 06/07/14 14:06, Gerriet M. Denkmann at <email_removed> wrote:
> On 14.07.2006, at 17:49, Jerry Krinock <<email_removed>> 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.
| Related mails | Author | Date |
|---|---|---|
| Gerriet M. Denkman… | Jul 14, 11:12 | |
| Jerry Krinock | Jul 14, 15:25 | |
| Adam R. Maxwell | Jul 14, 15:33 | |
| Gerriet M. Denkman… | Jul 14, 23:06 | |
| Jerry Krinock | Jul 15, 02:01 | |
| Gerriet M. Denkman… | Jul 15, 07:57 | |
| Jerry Krinock | Jul 15, 21:47 |






Cocoa mail archive

