Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-13-2010, 06:45 AM   #1 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default detecting timeout with NSURLConnection

I want to detect a timeout, but every time my app reaches the line to check for it, it crashes whether there was an error or not. Am I fundamentally not understanding how NSError works? Should I be implementing NSURLConnection with a delegate instead?

I've looked into this for several hours and can't make any headway and I'm pretty sure I'm just going about it in completely the wrong way. Any help in moving in the right direction would be greatly appreciated. Thanks in advance!

Code:
NSError *error;

NSURLRequest *ccRequest =
[NSURLRequest requestWithURL:[NSURL
                              URLWithString:[self createUrl]]
                 cachePolicy:NSURLRequestUseProtocolCachePolicy
             timeoutInterval:60.0];

NSURLResponse* response;

NSData* myData = [NSURLConnection sendSynchronousRequest:ccRequest 
                                       returningResponse:&response
                                                   error:&error];

// 1001 is the error code for a connection timeout
// It CRASHES below when it tries to determine the error code.
if ( error && [error code] == 1001 ) {
    NSLog( @"Server timeout!" );
}
__________________
German Course: Learn German anywhere! Chess Player: Study Chess anywhere!
chuck is offline   Reply With Quote
Old 09-13-2010, 08:47 AM   #2 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

I just changed the first line to:

Code:
NSError *error = nil;
and the bottom part to:

Code:
if ( error != nil && [error code] == 1001 ) {
When I look at the Debugger, it also doesn't have any information. Any other ideas?
__________________
German Course: Learn German anywhere! Chess Player: Study Chess anywhere!
chuck is offline   Reply With Quote
Old 09-13-2010, 09:10 AM   #3 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Also tried:

Code:
f ( myData == nil && [error code] == 1001 ) {
Same crash.
__________________
German Course: Learn German anywhere! Chess Player: Study Chess anywhere!
chuck is offline   Reply With Quote
Old 09-13-2010, 09:16 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Quote:
When I look at the Debugger, it also doesn't have any information. Any other ideas?
Have you tried running a backtrace in the d ebugger?
smithdale87 is offline   Reply With Quote
Old 09-13-2010, 09:46 AM   #5 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
Have you tried running a backtrace in the d ebugger?
How do you run a backtrace? When I load the debugger after the crash, there is nothing in it.
__________________
German Course: Learn German anywhere! Chess Player: Study Chess anywhere!
chuck is offline   Reply With Quote
Old 09-13-2010, 09:57 AM   #6 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

When the app crashes, and you open the debugger, type the word "backtrace" or just "bt" and it should spit out some more info about the crash
smithdale87 is offline   Reply With Quote
Old 09-14-2010, 04:15 AM   #7 (permalink)
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
When the app crashes, and you open the debugger, type the word "backtrace" or just "bt" and it should spit out some more info about the crash
Weird. That does absolutely nothing. Anything, I've since learned that synchronous NSURLConnection is buggy and I should use asynchronous instead. Anyway, thanks for the tip! I'm sure it will come in handy on future projects.
__________________
German Course: Learn German anywhere! Chess Player: Study Chess anywhere!
chuck is offline   Reply With Quote
Reply

Bookmarks

Tags
nsurlconnection, timeout

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 340
13 members and 327 guests
Absentia, cgokey, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, mraalex, PixelInteractive, raihan.zbr, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0