[英]How do I move from my html file to another html file to create an iOS hybrid app?
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
.
這部分成功插入html測試文件, html
加載也成功。
問題是當前頁面文件應該移動到其他html中的一個文件即。 之前頁面controller文件的地址由Java管理,頁面移動到地址值,但現在必須顯示html文件。
當前頁面控制器
public class PageController {
@RequestMapping("/index")
public String index(Map<String, Object> model) {
return "/index";
}
...
當前移動頁面
function pagemove(_url) {
location.href = _url; // url: "/nextPage"
}
當前的 WebViewLoad
func loadWebPage(_ webUrl : String) {
guard let myUrl = URL(string: webUrl) else {
//report invalid URL
return
}
let myRequest = URLRequest(url: myUrl)
WKWebView.load(myRequest)
}
現在我正在以這種方式移動屏幕。 如果我切換到 HTML,我該如何移動?
從 iOS 加載 Web 視圖(測試)
func loadWebPage(_ webUrl : String) {
let localFilePath = Bundle.main.url(forResource: "HTMLFolder/testweb", withExtension: "html")!
let myRequest = URLRequest(url: localFilePath)
WKWebView.load(myRequest)
}
我正在使用 Swift5
我想 go 從testweb.HTML文件到testwebTwo.HTML文件。
提前致謝。
目前,您的項目通過Java
內置的服務器進行管理。 但是現在您必須通過ios
項目中的html
文件移動您的頁面。
有兩種方法可以做到這一點。
首先,如果您將 webView 加載到html
文件中,您的 webView 會查看項目文件的路徑。 因此,在移動頁面時,也可以指定路徑。 示例是html
文件如何在同一路徑中並創建的示例。
function pagemove(_url) {
location.href = _url; // url: "./testwebTwo.html"
}
二、可以通過js
和native
通信收發消息來加載頁面數據。
js function
function testMovePage() {
var data = {};
data.movePage = "HTMLFolder/testwebTwo";
try {
webkit.messageHandlers.yourMessageKey.postMessage(data);
} catch (error) {
alert(error);
}
}
從 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)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.