简体   繁体   中英

Open some items in UIWebView, and others in external browser

I'm creating a html5 app, embed in UIWebView. I have delegate webview to controller, and on shouldStartLoadWithRequest, I'm looking for url pattern to open or not on external browser.

It's work perfect!

But when phone has no connection, I'm loading local html file. Because shouldStartLoadWithRequest return FALSE on first request, offline.html not loading

Anyone has do that?

在此处输入图片说明

Try this immediately after set path :

do {
    let path = NSBundle.mainBundle().pathForResource("offline", ofType: "html", inDirectory:"offline")
    let string = try String(contentsOfFile: path!, encoding:NSUTF8StringEncoding)
    webView.loadHTMLString(string, baseURL: NSURL(string: "http://"))
} catch {
    print(error)
}

or

let url = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("offline", ofType:"html", inDirectory: "offline")!)
let request = NSURLRequest(URL: url);
webView.loadRequest(request);

I tried it and it works.

Make sure your "offline" directory is a folder (BLUE) and not a group (YELLOW).

Hope this help.

I found the problem. I'm not triggering error -1003 (no host found)! removing switch work perfectly!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM