我一直在研究一个简单的应用程序,该应用程序可以对网站进行网页浏览,学生可以在其中进行考试。
所以基本上我的问题是,当学生完成后,他们必须单击将发送答案的按钮。将出现一个弹出窗口,使他们确认。https://i.stack.imgur.com/5GhB8.png除非它没有出现。按下按钮时什么也没有发生。它可以在Safari上完美运行,我注意到它可以在已弃用的Webview(UIWebview)上运行,但是我一直在尝试使其在WKWebView上运行。
我绝对不是敏捷专家,所以如果答案很简单,我深表歉意。我一直在寻找有关我的问题的答案,但是我不确定如何实现它。
预先感谢您的任何帮助,
import UIKit
import WebKit
class webViewController: UIViewController {
@IBOutlet weak var webview: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let lien = "***"
if let url = URL(string: lien) {
let request = URLRequest(url: url)
_ = webview.load(request);
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
我也遇到类似的问题,我的连接Facebook的弹出窗口不会在WKWebView中显示,但在野生动物园浏览器上可以正常工作。
此代码导致了问题。
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
//This condition was causing the problem while trying to get popup
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
我将其更改为以下代码,并且有效
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
if (navigationAction.targetFrame == nil) {
NSURL *tempURL = navigationAction.request.URL;
NSURLComponents *URLComponents = [[NSURLComponents alloc] init];
URLComponents.scheme = [tempURL scheme];
URLComponents.host = [tempURL host];
URLComponents.path = [tempURL path];
if ([URLComponents.URL.absoluteString isEqualToString:@"https://example.com/Account/ExternalLogin"]) {
WKWebView *webViewtemp = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
webViewtemp.UIDelegate = self;
webViewtemp.navigationDelegate = self;
[self.view addSubview:webViewtemp];
return webViewtemp;
} else {
[webView loadRequest:navigationAction.request];
}
}
return nil;
}
迅捷版:
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
let tempURL = navigationAction.request.url
var components = URLComponents()
components.scheme = tempURL?.scheme
components.host = tempURL?.host
components.path = (tempURL?.path)!
if components.url?.absoluteString == "https://example.com/Account/ExternalLogin" {
let webViewtemp = WKWebView(frame: self.view.bounds, configuration: configuration)
webViewtemp.uiDelegate = self
webViewtemp.navigationDelegate = self
self.view.addSubview(webViewtemp)
return webViewtemp
} else {
webView.load(navigationAction.request)
}
}
return nil
}
希望这对您有帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句