• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: runloops and NSURLConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: runloops and NSURLConnection


  • Subject: Re: runloops and NSURLConnection
  • From: Michael Vannorsdel <email@hidden>
  • Date: Sat, 31 May 2008 08:09:36 -0600

I think you want to schedule the connection for the NSModalPanelRunLoopMode runloop mode. This is the mode that is used for modal windows.


On May 31, 2008, at 7:28 AM, Torsten Curdt wrote:

A bit puzzled ...seems like I need some advise here.

From a NSWindowController I create a modal dialog

 [NSApp runModalForWindow:[self window]];

On a button click I am trying to use NSURLConnection to do retrieve information in a asynchronous fashion

connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

Unfortunately this only works when I afterwards enter this runloop

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
while(!terminated) {
if (![[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:100000]]) {
break;
}
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
[pool release];


(the connectionDidFinishLoading:/connection:didFailWithError: terminates the above loop)

Now I am a bit surprised. Shouldn't runModalForWindow: do pretty much the same thing? The documentation states

"By default, for the connection to work correctly the calling thread’s run loop must be operating in the default run loop mode. See scheduleInRunLoop:forMode: to change the runloop and mode."

But I am a bit lost what to do with that information. I would assume that

scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode

is the default anyway. Nevertheless I am targeting 10.4 and this is only available since 10.5.

I found this response from Fraser

http://lists.apple.com/archives/aperture-dev/2008/Feb/msg00036.html

...but I would like to understand the "why". Do I really have to spawn another thread for this? Or is it OK to process the run loop like shown above? I have the feeling I am somehow fighting the framework again here.

Comments?

cheers
--
Torsten_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: runloops and NSURLConnection
      • From: Torsten Curdt <email@hidden>
References: 
 >runloops and NSURLConnection (From: Torsten Curdt <email@hidden>)

  • Prev by Date: Re: Displaying current time using NSCalenderDAte
  • Next by Date: Re: Changing button title based on single or multiple selection?
  • Previous by thread: runloops and NSURLConnection
  • Next by thread: Re: runloops and NSURLConnection
  • Index(es):
    • Date
    • Thread