Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

counterhype

macrumors newbie
Original poster
May 29, 2009
8
0
Hello,

i'm new to iPhone Programming, so i apologize if i am missing something, or if this was answered somewhere else and I missed it.

So i'm getting the following error when trying to call [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString bytes]: unrecognized selector sent to instance 0x28114'

It should be noted that this line of code does work some of the time, but in this particular request it doesn't work consistently. I'm also new to XCode, so my debugging skills are rudimentary.

The code i'm using is here:

NSURLResponse* response = nil;
NSError* error = nil;
NSData* responseData;
@try
{
responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];

}
@catch (NSException *exception) {
NSLog(@"Caught %@%@", [exception name], [exception reason]);
}



Any help or direction would be most appreciated.

-haider
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The runtime exception you show indicates that string was used someplace that an NSData object was meant to be used. The string doesn't respond to bytes because that's an NSData method.

This kind of bug usually happens when an object, an NSData in this case, isn't properly retained. At a later time when it is used the NSData object has been released and its memory location has been reused by some other object, an NSString in this case.

How do you know that this runtime exception is happening inside the call to sendSynchronousRequest:?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.