Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection



If the operation you are trying to do is something pretty much guaranteed to be short, like authentication, then you could use NSURLConnection's convenience method that waits synchronously: sendSynchronousRequest

 
I use it since all I do with NSURLConnection is a quick authentication to Google while a modal progress sheet is displayed. It handles all the NSURLConnection requirements for run loops and threading so it's pretty handy. Of course, if you are doing a long post, like an upload or something, I would definitely not recommend the sync. call! Here's the code that I use it in:
http://dev.notoptimal.net/2008/02/google-clientlogin-in-objective-c.html

JI


On Wed, Feb 20, 2008 at 6:57 PM, Fraser Speirs <email@hidden> wrote:
On 20 Feb 2008, at 23:17, Micah Walter wrote:

> If I set this up in a standard Cocoa app, it works just fine, but in
> an Aperture plugin, the delegate handlers don't get called unless
> you click cancel or export on the plugin... I tried doing it in a
> new thread, but that didnt seem to work either... unless I just did
> it wrong..


NSURLConnection doesn't work in a modal runloop, such as Aperture
plugins exist within.  You have two choices:

1. Don't use NSURLConnection.  cURLHandle (or the bare C cURL API)
might be another possibility for you.

2. Interact with NSURLConnection in a background thread.  This is what
FlickrExport does:

- Spawns a new thread to a selector which starts the NSURLConnection
- Receives the NSURLConnection callbacks in the background thread
- Notifies the main thread by calling -
performSelectorOnMainThread:withObject:waitUntilDone:inModes: with
whatever data you want out of the NSURLConnection.

It's a pain, but it does work.  If you can require Leopard, I believe
there is some new stuff in NSURLConnection that makes it possible to
schedule them on modal runloops.

HTH,
Fraser
--
http://speirs.org -- http://connectedflow.com


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Aperture-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/aperture-dev/email@hidden

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Aperture-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/aperture-dev/email@hidden

This email sent to email@hidden

References: 
 >NSURLConnection (From: Micah Walter <email@hidden>)
 >Re: NSURLConnection (From: Fraser Speirs <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.