Swift iframe not loading in web view

2019-07-29 09:59发布

Basically, in a web view, my page loads fine, but the iframes in it never load, they just stay white or don't appear at all, this happens in both htmlstrings and NSURL sessions please help. code

import Darwin
import UIKit

class ViewController: UIViewController {
@IBOutlet var InterfaceX: UIWebView!
override func viewDidLoad() {
    super.viewDidLoad()
    sleep(1)

    let url=NSBundle.mainBundle().URLForResource("hi", withExtension: "html")
    //let url = NSURL(string: "http://creepertech.net/xe/interface")
    let request = NSURLRequest(URL: url!)
    InterfaceX.loadRequest(request)
    InterfaceX.allowsInlineMediaPlayback = true;

    //let htm:String! = "<head><header></header></head><body><iframe src=\"http://xegaming.com\"></iframe></body>"
    //InterfaceX.loadHTMLString(htm, baseURL: nil)


    // Do any additional setup after loading the view, typically from a nib.
}
override func prefersStatusBarHidden() -> Bool {
    return true
}

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


}

1条回答
SAY GOODBYE
2楼-- · 2019-07-29 10:35
    @IBOutlet weak var m_objWebView: UIWebView!

func CreateWebViewPlayer()
    { 
     self.m_objWebView.allowsInlineMediaPlayback = true

     let embededHTML = "<html><body><iframe src=\"URL HERE\"?playsinline=1\" width=\"320\" height=\"315\" frameborder=\"0\" scrolling=\"no\" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe></body></html>"

     self.m_objWebView.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL)
    }

NOTE :- Replace URL HERE with your actual URL

查看更多
登录 后发表回答