In article <uce-D3811F.18522906052008@[EMAIL PROTECTED]
>,
Gregory Weston <uce@[EMAIL PROTECTED]
> wrote:
> In article <6d6dnSly0L5RWr3VnZ2dnUVZ_qKgnZ2d@[EMAIL PROTECTED]
>,
> Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
>
> > One of these things consistently pukes...
> >
> > Forgive blown line ends in the code that follows... It's cut-n-pasted
> > directly from the project,
>
> Which puts you one step ahead of half the people who ask for help.
>
> > and the newsreader isn't too good at wrapping Objective-C!
> >
> > In the code that follows, if "TESTING" = 1, I get the expected result:
> > The instance variable (declared as "NSMutableData *Buffer;" in my .h
> > file) Buffer comes back filled with the HTML from MyURL.
> >
> > If "TESTING" !=1, Buffer comes back filled with random garbage.
> >
> > Likewise, when the first version gets used, the local NSData (Note NOT
> > mutable) TheData variable is loaded with the HTML that comes from
MyURL,
> > but when the second version is used, TheData contains random garbage.
>
> My first thought is that you're sort of overcomplicating things or
> reading things backwards. The issue is that [NSData
> dataWithContentsOfURL:MyURL] is not returning what you expect.
Aye - That it isn't. And I can't figure out why.
> Everything after that - in particular the fact that Buffer comes out
> wrong - is an obvious result.
Pretty much...
>
> Out of curiosity, are the first two bytes that you get back in the
> second case 1F and 8B?
Uh, lemme look...
Indeed - hexdumping TheData shows me a 1f 8b sequence at the start...
>
> If so, you appear to have run across a bug that was introduced 4+ years
> ago:
>
> <http://www.cocoabuilder.com/archive/message/cocoa/2004/3/22/102280>
Hrrrmmm... Color me bitten. That sure sounds like the symptoms.
And, unfortunately, the "workaround" is to use the method I used in
Version 1... That's some catch, that Catch-22! :)
>
> BTW: You really should avoid using synchronous downloads if you can.
From what I can see, I'd tend to agree - which is why I was trying to
hook into the "dataWithContentsOfURL" method. Or is that synchronous,
too?
Version 1 is the original, synchronous, "works fine" version.
Version 2 is my attempt to get away from the explicitly synchronous
thing, and let the transfer happen in the background - Although now that
I think about it further, dataWithContentsOfURL MUST be synchronous - So
is there a simple, non-sync way of doing the deed? I envision a fantasy
to the tune of "Here's a URL and a callback. Holler via the callback
when you've got the needed data so we can proceed"
>
> BTW2: In case one, these two lines are wrong:
>
> NSError *TheError = [NSError alloc];
> NSURLResponse *TheResponse = [NSURLResponse alloc];
>
> You should never alloc without a subsequent init.... More im****tantly,
> in the specific way you're using them, you should initialize the
> variables to nil instead of allocating space; they're output arguments.
> What you've got leaks.
Ah, OK... Something like this:
NSError *TheError = nil;
etc?
I thought I had to have an actual NSError/NSURLResponse, etc available
before I made the call. Guess that's what thinkin' does for me :)
--
Don Bruder - dakidd@[EMAIL PROTECTED]
- If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info


|