我的网址
我的发现
该网址适用于所有Safari和其他浏览器。 (包括iOS 11手机游戏)
该URL适用于iOS 11以外的所有iOS版本。
我尝试在UIWebView和WKWebView上打开URL,但两者都发生了同样的问题。即URL在完成时停止加载 那时没有任何事情发生。
这是我到目前为止所尝试的内容
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
// Objects
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
setupWebView()
loadUrl()
}
func setupWebView() {
let prefs = WKPreferences()
prefs.javaScriptEnabled = true
let config = WKWebViewConfiguration()
config.preferences = prefs
webView = WKWebView(frame: view.frame, configuration: config)
webView.navigationDelegate = self
view.addSubview(webView)
}
func loadUrl() {
webView.navigationDelegate = self
let url = URL(string: "https://app.educationgalaxy.com/games/ipadgame.html?retries=3&name=blastoff&rocket=3&level=2&score=0&gameTimer=150")!
var request = URLRequest(url: url)
request.cachePolicy = .reloadRevalidatingCacheData
webView.load(request)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print(webView.url!)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print(webView.url!)
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("error - \(error)")
}
}
感谢您的帮助。
答案 0 :(得分:0)
我已经分析了你的代码是好的,你需要检查图像格式。当我使用波纹管代码与图像url链接工作正常。
import UIKit
import WebKit
class ViewController: UIViewController ,WKNavigationDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
setupWebView()
loadUrl()
}
func setupWebView() {
let prefs = WKPreferences()
prefs.javaScriptEnabled = true
let config = WKWebViewConfiguration()
config.preferences = prefs
webView = WKWebView(frame: view.frame, configuration: config)
webView.navigationDelegate = self
view.addSubview(webView)
}
func loadUrl() {
webView.navigationDelegate = self
// let url = URL(string: "https://app.educationgalaxy.com/games/ipadgame.html?retries=3&name=blastoff&rocket=3&level=2&score=0&gameTimer=150")!
let url = URL(string: "https://upload.wikimedia.org/wikipedia/commons/2/2d/Snake_River_%285mb%29.jpg")!
var request = URLRequest(url: url)
request.cachePolicy = .reloadRevalidatingCacheData
webView.load(request)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print(webView.url!)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print(webView.url!)
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("error - \(error)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 1 :(得分:0)
最近推出了WkWebview,现在正式弃用UIWebView。 这是Apple论坛上发布的相同问题的链接。苹果工作人员目前正在查明崩溃。 enter link description here
https://forums.developer.apple.com/thread/90411 还尝试在项目中添加WKWebView.framework。 和运输安全。 希望这些信息可以帮到你。
答案 2 :(得分:0)
//添加plist文件
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>google.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
if WKWebView don't not support then declare .m file below code:
#import <WebKit/WebKit.h>
@interface WebScannerViewController()
{
WKWebView *webView;
}
@end
@implementation WebScannerViewController -(void)viewDidLoad {
[super viewDidLoad];
webView.hidden=YES;
webView.UIDelegate = self;
webView.navigationDelegate = self;
self.loadingSign.hidden = NO;
webView.frame=CGRectMake(0, 94, Width, Height-128);
webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
webView.customUserAgent = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17";
webView.navigationDelegate = self;
NSURL *url = [NSURL URLWithString:@"https://app.educationgalaxy.com/games/ipadgame.html?retries=3&name=blastoff&rocket=3&level=2&score=0&gameTimer=150"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
}