和我之前的其他人一樣,我有一些我想在我的應用中顯示的網頁內容。我的網站是在Microsoft Visual Web Developer中開發的基於ASP.NET的網站,它使用Ajax Toolkit和其他漂亮的插件。我可以在iPhone的移動Safari瀏覽器中打開該網站,甚至可以將一些適合移動設備的網頁放在一起。UIWebKit無效率
我(或更準確地說,我的老闆)想要一個iPhone應用程序,它存儲用於訪問我的網站的憑證,並在打開應用程序時自動發送它們。這裏的問題:
我的網站不加載在UIWebView。它不會遇到任何委託方法(完成加載,未能加載等)。它只是啓動連接請求並坐在那裏。該網站在我用於測試的同一設備上的Safari上工作,所以我認爲這個問題與UIWebKit沒有在Safari中構建的某些工具有關。
什麼(特別是)導致我的網站無法加載在UIWebKit,當它在Safari中正確加載?
我會後我已經設置了捕捉任何生命跡象,從我的電話的方法來
[myWebView loadRequest:myRequest];
無下列方法被調用時,我跑我的應用程序,並達到上述的loadRequest調用。
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"WillSendForAuthenticationChallenge");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Webview failed to load.");
if (error.code == NSURLErrorCancelled) return; // this is Error -999, called when the user forcibly ends the connection by starting a new connection.
UIAlertView *failure = [[UIAlertView alloc] initWithTitle:@"Failed" message:error.localizedDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[failure show];
[spinner stopAnimating];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"Loading request: %@",request.URL);
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
NSLog(@"Webview finished loading.");
[spinner stopAnimating];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"Can Authenticate: %@",[protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]);
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSLog(@"Received an authentication challenge.");
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
這是什麼問題? – Caleb 2012-03-07 21:10:52
對於任何人來幫助你這個,也許你可以告訴我們你當前如何通過證書到網站的情況下,它的工作(顯示一些代碼),以及你想如何使用UIWebKit(描述性)。 – Jim 2012-03-07 21:21:18
你設置了webview代理嗎? – fbernardo 2012-03-08 18:40:30