iT邦幫忙

0

objective c 彈出瀏覽器詢問

@implementation ViewController
    NSString *urlString = @"http://ad.hodomobile.com/webad/release_320x50.php";
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.mywebView loadRequest:request];
    [self.view addSubview:_mywebView];
    self.mywebView.scalesPageToFit = YES;
    
    self.mywebView.delegate = self;
}

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

    
    if(navigationType == UIWebViewNavigationTypeOther)
    {
        [[UIApplication sharedApplication] openURL: request.URL];
    return NO;
    }
    return YES;
}

想請問網址是一個廣告banner,我用webView做顯示,要點擊後彈出瀏覽器呈現網站,
但是跑模擬器時,卻廣告還沒出來,也還沒點擊,就直接彈出瀏覽器顯示廣告,是哪個地方我有寫錯了嗎....

1 個回答

0
海綿寶寶
iT邦超人 1 級 ‧ 2016-06-29 08:45:31

底下這整段刪掉試看看...

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

    
    if(navigationType == UIWebViewNavigationTypeOther)
    {
        [[UIApplication sharedApplication] openURL: request.URL];
    return NO;
    }
    return YES;
}

我實在看不懂,你的 urlString 是「網站」還是「廣告」...
反正 WebView 只會傻傻的顯示你要他顯示的 url 就是了

yugochen iT邦新手 5 級 ‧ 2016-06-29 09:34:42 檢舉

是一個廣告,但是我試著想讓他點擊後呈現出符合手機螢幕大小的網站

我要發表回答

立即登入回答