I'd like to replace a webView
page with a Spring-MVC
structure with a hybrid format So I'd like to replace the JSP
file with an HTML
file and put it in the ios project folder
.
This part successfully inserted the html test file, and the html
load was also successful.
The problem is the current page file should be moved to other html in a file that is. Previously, the address of the page controller file was managed by Java, and the page was moved to the address value, but now the html file must be displayed.
current PageController
public class PageController {
@RequestMapping("/index")
public String index(Map<String, Object> model) {
return "/index";
}
...
current move page
function pagemove(_url) {
location.href = _url; // url: "/nextPage"
}
curerent WebViewLoad
func loadWebPage(_ webUrl : String) {
guard let myUrl = URL(string: webUrl) else {
//report invalid URL
return
}
let myRequest = URLRequest(url: myUrl)
WKWebView.load(myRequest)
}
Now I'm moving the screen in this way. How can I move if I switch to HTML?
Loading Web Views from iOS(testing)
func loadWebPage(_ webUrl : String) {
let localFilePath = Bundle.main.url(forResource: "HTMLFolder/testweb", withExtension: "html")!
let myRequest = URLRequest(url: localFilePath)
WKWebView.load(myRequest)
}
I'm using Swift5
I want to go to the testwebTwo.HTML file from the testweb.HTML file.
Thanks in advance.
Currently, your project is managed through a server built in Java
. But now you have to move your page through the html
file inside the ios
project.
There are two ways in order to so.
Firstly, if you load a webView into an html
file, your webView looks at the path to the project file. Therefore, when you move pages, you can also specify a path. An example is an example of how html
files are in the same path and created.
function pagemove(_url) {
location.href = _url; // url: "./testwebTwo.html"
}
Second, you can load page data by sending and receiving messages through js
and native
communication.
js function
function testMovePage() {
var data = {};
data.movePage = "HTMLFolder/testwebTwo";
try {
webkit.messageHandlers.yourMessageKey.postMessage(data);
} catch (error) {
alert(error);
}
}
Receive From Swift
@available(iOS 8.0, *)
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "yourMessageKey" {
let sendmessage = message.body as! NSDictionary
guard sendmessage["movePage"] != nil else {
return
}
let urlString : String = sendmessage["movePage"] as! String
let filePath = Bundle.main.url(forResource: urlString, withExtension: "html")
let request = URLRequest(url: filePath)
WKWebView.load(request)
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.