unrecognized selector problem with NSURLConnection sendSynchronousRequest

Discussion in 'iOS Programming' started by counterhype, May 29, 2009.

  1. counterhype macrumors newbie

    Joined:
    May 29, 2009
    #1
    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
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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:?
     
  3. counterhype thread starter macrumors newbie

    Joined:
    May 29, 2009
    #3
    thanks a lot for looking into it. i actually got the problem fixed now.
     

Share This Page