2010-11-26 8 views

답변

0

웹보기에서 현재 URL의 내용을 가져와야하는 경우 UIViewController에서 이와 같은 내용을 사용할 수 있습니다. 이 코드를 컴파일하지 않았으므로 구문 오류가있을 수 있지만 문제의 시작점이되어야합니다.

@interface aViewController : UIViewController <UIWebViewDelegate> 
    UIWebView *webView; 
    NSString *htmlSource; 
@end 
@implementation aViewController 

-(void) viewDidLoad { 
    CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; 

    self.webView = [[UIWebView alloc] initWithFrame:webFrame]; 
    self.webView.delegate = self; 

    NSURL *aURL = [NSURL URLWithString:@"http://www.myurl.com"]; 
    NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL]; 
    //load the index.html file into the web view. 
    [self.webView loadRequest:aRequest]; 
}  
//This is a delegate method that is sent after a web view finishes loading content. 
- (void)webViewDidFinishLoad:(UIWebView *)webView{ 
    NSLog(@"finished loading"); 
    self.htmlSource = [[NSString alloc] initWithData:[[webView request] HTTPBody] encoding:NSASCIIStringEncoding]; 
} 

@end 
+0

동일한 URL에 대한 두 번의 요청은 오류 응답의 기회를 두 배로하고, 일관성없는 응답의 가능성을 추가하며, 라디오 사용을 늘립니다. 캐싱을 통해 이러한 문제를 완화 할 수 있지만 데이터가 이미있는 경우 캐싱을 사용하는 이유는 무엇입니까? –

+0

동일한 URL에 대한 두 건의 요청으로 무엇을 언급하고 있습니까? – Travis

+0

아, 무슨 뜻인지 알 겠어. UIWebView의 NSURLRequest HTTPBody를 기반으로 소스를 검색하도록 업데이트했습니다. – Travis

1

JavaScript가 stringByEvaluatingJavaScriptFromString :을 사용하여 반환 할 수있는 웹보기에서 무엇이든 얻을 수 있습니다.

document.lastChild.outerHTML 

행을 따라 무언가를 시도하십시오. 문서에 두 개의 하위 노드가있을 수 있습니다. 첫 번째는 DOCTYPE이고 두 번째는 <html> 요소입니다.

관련 문제