0

UIImageをサーバーにアップロードするアプリを書いています。写真が追加されているのを見ると、これは完璧に機能します。画像データにUIImageJPEGRepresentationを使用し、NSMutableRequestを構成します。(URL、httpメソッド、境界、コンテンツタイプ、およびパラメーターの設定)

ファイルがアップロードされているときにUIAlertViewを表示したいので、次のコードを記述しました。

//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]; 

returnStringの出力:2010-04-22 09:49:56.226 bbc_iwh_v1 [558:207]戻り情報:OK

問題は、AlertViewが取得されないため、ifステートメントでreturnstring ==@"OK"と表示されないことです。

このリターンストリング値を確認するにはどうすればよいですか?

4

1 に答える 1

2

問題は、returnString がポインターであることです。

NSString * returnString;

あなたが言う時:

if ( returnString == @"OK" )

2 つの文字列ではなく、2 つのポインターを比較しようとしています。

文字列を比較する正しい方法は次のとおりです。

if ([returnString isEqualToString:@"OK"])
{
    //do what you want
}
于 2010-09-01T09:02:57.603 に答える