こんにちはASIHTTPRequest
、Web サーバーへのログインに使用するアプリがあります。ユーザー名とパスワードが両方とも正しい場合、loginRequestFinished
が呼び出されます。ただし、ログイン資格情報が正しくない場合、loginRequestFinished
も も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 に渡した方法です。theRequest を渡すには userInfo を使用する必要があることに気付きました。