Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 无法调用列表类型为NSURL的加载数据…正在加载本地web视图内容_Swift_Uiwebview_Swift2_Nsurl - Fatal编程技术网

Swift 无法调用列表类型为NSURL的加载数据…正在加载本地web视图内容

Swift 无法调用列表类型为NSURL的加载数据…正在加载本地web视图内容,swift,uiwebview,swift2,nsurl,Swift,Uiwebview,Swift2,Nsurl,我试图通过webview对象创建一个在后台播放mp4的登录页面。这是我的代码,错误在这一行 webView.loadData(url!, MIMEType: "video/mp4", textEncodingName: String(), baseURL: NSURL()) 错误是 "cannot invoke 'loadData' with argument list of type'(NSURL....'" 我不知道下一步该怎么办。先谢谢你 class ViewController:

我试图通过webview对象创建一个在后台播放mp4的登录页面。这是我的代码,错误在这一行

webView.loadData(url!, MIMEType: "video/mp4", textEncodingName: String(), baseURL: NSURL()) 
错误是

"cannot invoke 'loadData' with argument list of type'(NSURL....'"
我不知道下一步该怎么办。先谢谢你

class ViewController: UIViewController {

@IBOutlet var webView: UIWebView!

var moviePlayer: MPMoviePlayerController!

func loginVideo(){

    webView.frame = self.view.frame

    let filePath = NSBundle.mainBundle().pathForResource("movie", ofType:"mp4")
    let url = NSURL.fileURLWithPath(filePath!)

    webView.loadData(url!, MIMEType: "video/mp4", textEncodingName: String(), baseURL: NSURL())
    webView.userInteractionEnabled = false;

    let filter = UIView()
    filter.frame = self.view.frame
    filter.backgroundColor = UIColor.blackColor()
    filter.alpha = 0.05
    self.view.addSubview(filter)
}
}

您必须使用NSData代替URL。loadData方法的实际签名为

wkWebView.loadData(data: NSData, MIMEType: String, characterEncodingName: String, baseURL: NSURL)
尝试替换下面的行

let url = NSURL.fileURLWithPath(filePath!)
webView.loadData(url!, MIMEType: "video/mp4", textEncodingName: String(), baseURL: NSURL())


不幸的是,这给了我一个错误“找不到接受String()类型参数的NSData初始值设定项”,我使用了
let data=(NSBundle.mainBundle().pathForResource(“movie”,of type:“mp4”)!。dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion:false)webView.loadData(数据,MIMEType:“视频/mp4”,textEncodingName:String(),baseURL:NSURL())
唯一的问题是Sinulator没有播放视频。
let data = NSData(filePath!)
webView.loadData(data, MIMEType: "video/mp4", textEncodingName: String(), baseURL: NSURL())