2012-02-03 7 views
1

GETプロセスの結果について、データがサーバーに送信されるかどうかをユーザーに知らせる必要があります。誰でも私に方法に​​ついてのアイデアを与えることができますか?iphoneでGET/POSTリクエストの結果をユーザーに通知するにはどうすればよいですか?

注:私のユーザーインターフェイスの1つにいくつかのボタンがあり、ユーザーがそれらをクリックすると、いくつかのデータがサーバーに送信されます。このリクエストの結果についてユーザーにどのように伝えることができますか?おかげで..

EDIT

-(IBAction)theAction:(id)sender{ 

    NSString *key1=[[NSUserDefaults standardUserDefaults] valueForKey:@"keyToKey"]; 
    NSString *userID=[[NSUserDefaults standardUserDefaults] valueForKey:@"userID"]; 
    NSLog(@"\nButton ID: %d-",[sender tag]); 
    NSString *str1= [[@"http://" stringByAppendingString:serverF.text] stringByAppendingString:@"/request.php?"]; 
    NSString *str2= [[str1 stringByAppendingString:@"key="] stringByAppendingString:key1]; 
    NSString *str3= [[[[str2 stringByAppendingString:@"&userID="]stringByAppendingString:userID] stringByAppendingString:@"&button_tag="]stringByAppendingString:[ sender tag]]; 
    NSURL *theUrl=[NSURL URLWithString:str3]; 

    // What shall i do from here?, or is this way true??? 



} 

私はこの時点から、何が必要ですか?

+0

あなたはNSURLConnectionを使用していますか?あなたのサーバーにそのデータをどのように送信しているか、もう少し詳細を教えてください。 –

+0

@ sgermain06私の編集 –

答えて

1

あなたは、GET HTTPリクエストのためにGETresponseで結果を持っています:

NSString *GETresponse=[NSString stringWithContentsOfURL:[NSURL URLWithString:str] encoding:NSUTF8StringEncoding error:nil]; 
+2

これは同期要求ですので、質問に記載されているUIスレッドをブロックします。より良い解決策は[NSURLConnection](https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/doc/uid)の使用です。/TP40003755) '+ sendAsynchronousRequest:queue:completionHandler:' –

+0

これはまさに答えです。あなたはそれを使って質問を編集できます:)ありがとう –

1

快適な方法は、ASI HTTPを使用することです。 http://allseeing-i.com/ASIHTTPRequest/How-to-use 次に、あなたの要求の結果がである:場合に

- (void)requestFinished:(ASIHTTPRequest *)request 

あなたの要求は、それが失敗したsuccessfuly終了、または場合

- (void)requestFailed:(ASIHTTPRequest *)request 

。必要に応じて、キュー、同期、および非同期要求を選択できます。

+0

をありがとうrhatありがとうが、私のアプリでASIHTTPRequestライブラリのいくつかの問題に直面した。それ以外の方法はありませんか? –

+0

はい、[NSURLConnection](https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/doc/uid)を使用してください。/TP40003755)を 'sendAsynchronousRequest:queue:completionHandler:'と置き換えてください。 –

1

あなたはこの単一のメソッドと同じ文字列を取得することができます。このコードで

NSString *str = [NSString stringWithFormat: 
       @"http://%@/request.php?key=%@&userID=%@&button_tag=%@", 
       serverF.text, key1, userID, [sender tag] ]; 
+0

賢明な解決策:Dしかし私はこれが私の質問への答えだったらいいと思っています:) –

関連する問題