urlConnectionを開く2つのボタンを持つViewController.mファイルがあり、応答を処理する必要があります。私の問題は、接続がボタン1(アビリタ)またはボタン2(ログイン)から来る場合、デリゲートで理解できないことです。私に何ができる?
-(IBAction)abilita {
NSString *usernameEncoded = [username.text urlencode];
NSString *passwordEncoded = [password.text urlencode];
NSString *mittenteEncoded = [abilitaField.text urlencode];
NSString *code=@"abcdef";
NSString * address = [NSString stringWithFormat:@"http://www.xxx.net/smsweb/setsender/recsender.php?login=%25%40&password=%25%40&codice%@",usernameEncoded, passwordEncoded,code];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:address]];
urlConnectionRecsender=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
}
- (IBAction)login {
NSString * address = [NSString stringWithFormat:@"http://www.xxx.net/smsscript/sendsms.php?login=%25%40&password=%25%40&tipo=2",usernameEncoded, passwordEncoded];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:address]];
urlConnectionLogin=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
}
//DELEGATE:
- (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)response
{
mutableData = [NSMutableData data] ;
if ([conn isEquals:urlConnectionRecsender]){
// this is request urlConnectionRecsender
}
if ([conn isEquals:urlConnectionLogin]){
// this is request urlConnectionLogin
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn
{
NSMutableString *stringData = [[NSMutableString alloc] initWithData:mutableData encoding: NSASCIIStringEncoding];
}
connectionDidFinishLoadingで理解できる方法でコードを記述できますか?どの接続を処理していますか?