嗨,我有一个ASIHTTPRequest
用于登录 Web 服务器的应用程序。当用户名和密码都正确时,loginRequestFinished
调用。但是,当登录凭据不正确时,不会调用theloginRequestFinished
和 the 。loginRequestFailed
我试图通过实现一个来解决这个问题,NSTimer
以便它会给出一条错误消息并在 60 秒后取消请求。但是看起来请求已经dealloc
到那时(我发现这很奇怪,因为状态栏中的加载指示器仍在旋转)。
这是我得到的错误:
-[__NSCFTimer cancel]: unrecognized selector sent to instance 0x84f0720
(lldb)
这是我的代码:
- (void) login
{
NSString* url = [NSString stringWithFormat:@"https://%@/local_login.html", self.serverIP];
ASIHTTPRequest *theRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[theRequest setDelegate:self];
[theRequest setUsername:username];
[theRequest setPassword:password];
[theRequest setDidFinishSelector:@selector(loginRequestFinished:)];
[theRequest setDidFailSelector:@selector(loginRequestFailed:)];
[theRequest startAsynchronous];
myTimer = [NSTimer scheduledTimerWithTimeInterval:60.0f
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:NO];
}
- (void)timerFired:(ASIHTTPRequest *)request
{
[myTimer invalidate];
UIAlertView *warning = [[[UIAlertView alloc] initWithTitle:@"Error" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]autorelease];
[warning show];
[request cancel];
[request release];
}
任何帮助将不胜感激
更新: 我检查了服务器日志。如果我输入的密码或用户名不正确,我的应用程序每秒都会向服务器发送登录请求,直到我退出 iPhone 模拟器。
2013-09-11 16:22:02.187 /local_login.html 401 91ms 0kb EC 1.0.1 (iPhone Simulator; iPhone OS 6.1; en_US)
150.101.105.182 - - [11/Sep/2013:16:22:02 -0700] "GET /local_login.html HTTP/1.1" 401 404 - "EC 1.0.1 (iPhone Simulator; iPhone OS 6.1; en_US)" "xyz.appspot.com" ms=91 cpu_ms=0 cpm_usd=0.000045 app_engine_release=1.8.4 instance=00c71b118abd13a90c30bcf64033c95172a494
2013-09-11 16:22:01.754 /local_login.html 401 29ms 0kb EC 1.0.1 (iPhone Simulator; iPhone OS 6.1; en_US)
150.101.105.182 - - [11/Sep/2013:16:22:01 -0700] "GET /local_login.html HTTP/1.1" 401 404 - "EC 1.0.1 (iPhone Simulator; iPhone OS 6.1; en_US)" "xyz.appspot.com" ms=30 cpu_ms=21 cpm_usd=0.000045 app_engine_release=1.8.4 instance=00c71b118abd13a90c30bcf64033c95172a494
(More Similar log events)
谢谢大家。问题已解决。这是我将 ASIHTTPRequest 传递给 myTimer 的方式。我意识到我必须使用 userInfo 来传递请求。