views:

247

answers:

1

hi all,

I'm writing an app which uploads a UIImage to my server. This works perfect, as I see the pictures being added. I use the UIImageJPEGRepresentation for the image data and configure an NSMutableRequest. ( setting url, http method, boundary, content types and parameters )

I want to display an UIAlertView when the file is being uploaded and I wrote this code:

//now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"return info: %@", returnString);

if (returnString == @"OK") {
    NSLog(@"you are snapped!");
    // Show message image successfully saved
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"You are snapped!" message:@"BBC snapped your picture and will send it to your email adress!" delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

[returnString release]; 

The returnString outputs: 2010-04-22 09:49:56.226 bbc_iwh_v1[558:207] return info: OK

The problem is that my if statements does not say returnstring == @"OK" as I don't get the AlertView.

How should I check this returnstring value?

A: 

The problem is that returnString is a pointer:

NSString * returnString;

When you say:

if ( returnString == @"OK" )

you are trying to compare two pointers, not two strings.

The right way to compare strings is:

if ([returnString isEqualToString:@"OK"])
{
    //do what you want
}
Anton Chikin