On 30 Apr 2009, at 05:31, Nick Hristov wrote:

Hello,

I am currently working on a small iphone app, and I am facing some
difficulty with getting NSURLConnection to ... connect. Basically my unit
tests don't pass: connection is never made.

Here is a snippet of the non-working code:

<code>

- (id) initWithURL: (NSURL*) someurl
{
   self = [super init];
   if (self != nil) {
       self->url = [someurl copy];
       NSURLRequest * request = [NSURLRequest requestWithURL:self->url
cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 6.0];
NSLog([NSString stringByAppendingStrings:@"Request: " , [request
description], nil]);
       self->finished = NO;
       self->connection = [[NSURLConnection alloc]
initWithRequest:request    delegate:self startImmediately:NO];
   }
   return self;
}

- (void) downloadData
{
   NSLog([self->connection description]);
   NSLog(@"run, b*$#4rd, run...");
   [self->connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
   [self->connection start];
   int timeout = 30;
   int i = 0;
while(self->finished == NO && [self _deletegateTerminateCheck] == NO) {
       // suspend thread
       [NSThread sleepForTimeInterval: 1.0];

I expect the above line is the problem ... if you suspend the thread then it presumably can't connect to the remote system. You would probably need to repeatedly run the current runloop using the -runMode:BeforeDate: method instead of suspending the thread.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to