负载网址
问题描述:
你好,我创建一个QR码阅读器和工作的伟大,但在Safari THETA打开网址,我想在我的WebView Swift在另一个场景中打开它负载网址
if metadataObj.type == AVMetadataObjectTypeQRCode {
// If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj as AVMetadataMachineReadableCodeObject) as! AVMetadataMachineReadableCodeObject
qrCodeFrameView?.frame = barCodeObject.bounds;
if metadataObj.stringValue != nil {
messageLabel.text = metadataObj.stringValue
//if the result is url...
UIApplication.sharedApplication().openURL(NSURL(string: metadataObj.stringValue)!)
}
}
答
的OpenURL会让设备处理这个URL,除非你的应用程序有一个定义的URL方案,它匹配它可能传递给Web浏览器的URL,除非另一个应用程序处理该方案。
如果你想呈现在网页视图,createa网页视图,并通过在要加载网址...
if metadataObj.type == AVMetadataObjectTypeQRCode {
// If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj as AVMetadataMachineReadableCodeObject) as! AVMetadataMachineReadableCodeObject
qrCodeFrameView?.frame = barCodeObject.bounds;
if metadataObj.stringValue != nil {
messageLabel.text = metadataObj.stringValue
//if the result is url...
let url = NSURL(string: metadataObj.stringValue)!
let request = NSURLRequest(url: url)
webView.loadRquest(request)
}
}
我建议把那些让一个声明,如果让代替赶上任何错误,但这是基本原则。
你只需要web视图添加到视图
我有2个不同的文件的Web查看其在* ViewController.swift * 和QR码扫描仪其* QRRViewController.swift * – d00nn123
好吧,你在哪里想要显示网页视图? – Scriptable
我想要从QR码(连接类QRRViewController.swift)扫描后显示webview中的网站(连接类ViewController.swift) – d00nn123