I have an iPhone application that is reading string data over an AsyncSocket. The weird part is that the msg received will not print to NSLog (it shows up in the console as just a blank). But if I pass the same msg to UIAlertView it shows just fine. Any ideas on what is going on, and how I can get this msg into an NSString that I can actually deal with? The code is below:
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length] - 2)];
NSString *msg = [[[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding] autorelease];
//this always prints in the console as 'msg received =' without the value of msg
NSLog(@"msg received = %@",msg);
//this actually pops up a dialog and shows the value of msg
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];
}