Load local html into UIWebView using swift

前端 未结 13 2085
耶瑟儿~
耶瑟儿~ 2020-11-28 22:27

This one is driving me crazy early this morning. I want to load some local html into a web view:

class PrivacyController: UIViewController {

    @IBOutlet w         


        
13条回答
  •  囚心锁ツ
    2020-11-28 23:06

    This is worked for me:

    @IBOutlet weak var mWebView: UIWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        mWebView.loadRequest(NSURLRequest(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("fineName", ofType: "html")!)))
    
    }
    

    Added App Transport Security Settings with Dictionary type in info.plist file. Also added sub key Allow Arbitrary Loads for App Transport Security Settings with type Boolean and value YES.

    Here is tutorial.

    EDITED

    For Swift 3 (Xcode 8)

    mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "test/index", ofType: "html")!)))
    

提交回复
热议问题