2

我在 iPhone 应用程序中工作,使用 Webview 在屏幕底部加载 Addvertisement 并且工作正常,我想当用户选择 WebView 时,它会自动转到浏览器并加载到 iPhone 设备中,如何集成?请帮我

提前致谢

我试过这个:

- (void)viewDidLoad
{

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 430, 320, 50)];
[webView setDelegate:self];
NSString *urlAddress = @"http://www.dasfafa./myadds.html";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
}

-(void)webViewDidStartLoad:(UIWebView *)webView 
{

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    NSString *currentURL = self.AddvertiseWebView.request.URL.absoluteString;
    NSLog(@"currentURL:%@",currentURL);

}
4

1 回答 1

4

此处的代码向您展示了在您的 UIWebView 中单击时如何在 Safari 中打开链接。方法 shouldStartLoadWithRequest 是一个委托方法,在单击链接时调用。您可以覆盖该方法并告诉它在 Safari 中打开。

- (BOOL)webView:(UIWebView *)webView 
     shouldStartLoadWithRequest:(NSURLRequest *)request
     navigationType:(UIWebViewNavigationType)navigationType; {

    NSURL *requestURL = [ [ request URL ] retain ]; 
    // Check to see what protocol/scheme the requested URL is.
    if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] 
        || [ [ requestURL scheme ] isEqualToString: @"https" ] ) 
        && ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
        return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ]; 
    }
    // Auto release 
    [ requestURL release ];
    // If request url is something other than http or https it will open 
    // in UIWebView. You could also check for the other following 
    // protocols: tel, mailto and sms
    return YES;
}

或试试这个

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }

    return YES; }
于 2012-09-08T09:48:11.993 回答