我有一个 ViewController.m 文件,其中有 2 个打开 urlConnection 的按钮,我需要处理响应。我的问题是当连接来自按钮 1(abilita) 或按钮 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中我能理解的方式编写代码吗?我在处理什么连接?