iT邦幫忙

0

swift webView顯示問題

想請問,我用webView顯示下面連結,點擊後使用safari開啟網頁但無法變成跳轉後的網址,這種有其他解法嗎??ㄋ

//
// ViewController.swift
// textWeb
//
// Created by Ed on 2016/6/8.
// Copyright © 2016年 ew. All rights reserved.
//

import UIKit
import WebKit

class ViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!
//var webView:UIWebView!;
let url = NSURL(string:"http://ad.hodomobile.com/webad/release_320x50.php");

override func viewDidLoad() {
    super.viewDidLoad()
    
    let request = NSURLRequest(URL: url!);
    
    webView.loadRequest(request);
    webView.scalesPageToFit = true;
    
    webView.delegate = self;
    self.view.addSubview(webView);
   

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

extension ViewController:UIWebViewDelegate{
func webView(webView: UIWebView,
shouldStartLoadWithRequest request: NSURLRequest,
navigationType navigationType: UIWebViewNavigationType) -> Bool{
if (navigationType == .LinkClicked){
UIApplication.sharedApplication().openURL(url!);
//UIApplication.sharedApplication().canOpenURL(url!);
return false;
}
return true;
}

}

尚未有邦友回答

立即登入回答