UIWebView に安全な Web サイトをロードしようとしています。私の基本的なアプローチは、NSURL、na NSURLRequest、次に NSURLConnection を作成し、次に NSURLRequest を UIWebView にロードすることです。ウェブサイトが読み込まれると、私は受け取ります
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
チャレンジ送信者に応答します
- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
しかし、その後は何も得られません...ハングするだけです。私はブレークポイントを入れたので、それを知っています
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
が呼び出されています。NSURLConnection が完了しないことが確実になるまで待ってからビューをリロードすると、認証チャレンジは送信されませんが、ビューはロードされます。サーバーを制御することはできません。私は AFNetworking を使用することにオープンですが、必要な場合のみです。
ソース コードの完全なリストを以下に示します。
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if ([challenge previousFailureCount] == 0)
{
NSString *username = @"username";
NSString *password = @"passsword";
NSURLCredential * cred = [NSURLCredential credentialWithUser:username
password:password
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}
else
{
}
}
-(void)updateCard
{
NSURL * url = [NSURL URLWithString:@"https://ssl.letu.edu/applications/chapelattendance/attendance.html"];
NSURLRequest * request = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:50.0];
self.webView =[[UIWebView alloc] initWithFrame:self.bounds];
self.webView.delegate = self;
[self.webView loadRequest:request];
self.connection = [[ NSURLConnection alloc]initWithRequest:request delegate:self];
[self.connection start];
}
どこで私は間違えましたか?