在 iOS 上的 PhoneGap 或 Cleaver (Cordova) 中加载远程 html

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14818138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:15:21  来源:igfitidea点击:

Loading remote html in PhoneGap or Cleaver (Cordova) on iOS

ioscordovauiwebview

提问by Moonwalker

I am using an Cordova 2.4 component Cleaver and an embedded view in my native iOS 6 application. So far I have managed to create the project structure, link the Cordova libraries and set up the Hello World app that does work providing "Device Ready" feedback.

我在我的原生 iOS 6 应用程序中使用 Cordova 2.4 组件 Cleaver 和嵌入式视图。到目前为止,我已经成功地创建了项目结构,链接了 Cordova 库并设置了 Hello World 应用程序,该应用程序可以提供“设备就绪”反馈。

This is all great but it loads all html from the www repository distributed inside the app itself (including all js libraries).

这一切都很棒,但它从分布在应用程序本身内部的 www 存储库(包括所有 js 库)加载所有 html。

What I really want yo do is this:

我真正想让你做的是:

1 - popup the cleaver component (which is nothing else than an embedded uiwebview) in my app. Easy - done.

1 - 在我的应用程序中弹出 cleaver 组件(它只不过是一个嵌入式 uiwebview)。容易 - 完成。

2 - load some html content from a URL pointing to a servlet on my remote server. I have several servlets and need to be able to load each one of them separately of course.

2 - 从指向远程服务器上的 servlet 的 URL 加载一些 html 内容。我有几个 servlet,当然需要能够分别加载它们中的每一个。

3- have the content generated in step 2 interact with my native app via the cordova javascript libs cordova-2.4.0.js - (how do I load these if they are local to device but html was loaded from remote location).

3- 让第 2 步中生成的内容通过cordova javascript libs cordova-2.4.0.js 与我的本机应用程序交互(如果它们是设备本地的,但html 是从远程位置加载的,我该如何加载)。

How can I set this up ?

我该如何设置?

P.S.

聚苯乙烯

I am more of Obj-C than Javascript developer :)

我更喜欢 Obj-C 而不是 Javascript 开发人员 :)

回答by Moonwalker

Here is the answer. What a joy...

这是答案。多么快乐...

excellent article on dynamic page loading in PhoneGap and Cordova

关于 PhoneGap 和 Cordova 中动态页面加载的优秀文章

Precisely what I needed. The second part of the project was to enable native code to force the loading of external web services - I accomplished this by called stringByEvaluatingJavaScriptFromString on the Cleaver web view .

正是我所需要的。该项目的第二部分是启用本机代码以强制加载外部 Web 服务 - 我通过在 Cleaver Web 视图上调用 stringByEvaluatingJavaScriptFromString 来实现这一点。

[webview stringByEvaluatingJavaScriptFromString:@"app.loadExternal('www.usatoday.com')];is the code that works like a charm:)

[webview stringByEvaluatingJavaScriptFromString:@"app.loadExternal('www.usatoday.com')];是像魅力一样工作的代码:)

Viola - I have a Cleaver view capable of loading external html content with complete two-way communication between the javascript app and the native container.

Viola - 我有一个 Cleaver 视图,能够通过 javascript 应用程序和本机容器之间的完整双向通信加载外部 html 内容。

回答by elio.d

Inside your index.html file do something like this (for the point 2)

在你的 index.html 文件中做这样的事情(对于第 2 点)

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript">
     function onBodyLoad(){     
        document.addEventListener("deviceready", onDeviceReady, false);
     }
     function onDeviceReady(){
         window.location.href = <your_remote_url>
     }
}
</script>

For the point 3, your remote content should import cordova.js and the interaction (native / web) will work as if it was local content.

对于第 3 点,您的远程内容应导入 cordova.js,并且交互(本机/网络)将像本地内容一样工作。