如何从远程页面访问到PhoneGap的API [英] How to get access to phonegap API from a remote page

查看:328
本文介绍了如何从远程页面访问到PhoneGap的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要以下情况: 我有一个已经存在的远程网页,我想向发展一个应用程序使用此页面。 到目前为止,一切都很好。当我启动应用程序的本地 index.html的加载和重定向(的window.open目标:_self )以外部网站。这个网站是在PhoneGap的web视图打开。在外部网站,我加了 cordova.js ,以获得访问本机的PhoneGap API。但它不能正常工作。在 deviceReady 事件被触发正确的,但我到PhoneGap的API不能访问,例如navigator.camera。

I have to following situation: I have a already existing remote webpage and i want to develope an app which uses this page. So far, so good. When I start the app the local index.html is loaded and it redirects (window.open target: _self) to the external website. This website is opened in the phonegap webview. On the external website I added the cordova.js in order to get access to the native phonegap API. But it doesn't work correctly. The deviceReady event is triggered correctly, but I have no access to the phonegap API, for example navigator.camera.

我怎样才能得到它做了,才能访问的API?

How can I get it done, to get access to the API?

请不要评论,这将通过苹果商店等等等等被拒绝。

Please do not comment that it will be rejected by AppStore etc. etc.

感谢您的帮助!

推荐答案

包括在远程站点的cordova.js脚本将是棘手的,因为有不同的cordova.js为每个平台。你可以修改服务器,使其返回基于用户代理的正确cordova.js,而这也是棘手,因为当您从一个移动浏览器的网站,它会包含这个脚本,这是不可取的,因为JavaScript错误可能会显示给用户。当从一个桌面计算机查看的网站,该cordova.js不应包括相同的故事。

Including the cordova.js script in the remote site is going to be tricky, because there's a different cordova.js for each platform. You could modify the server so that it returns the correct cordova.js based on the user agent, but this is also tricky because it will include this script when you view the site from a mobile browser, and this is undesirable because javascript errors might be shown to the user. Same story when viewing the site from a desktop computer, the cordova.js should not be included.

在我看来,你有一个本地的网页(与科尔多瓦剧本在内),并从那里可以切换到远程页面(也包括脚本)。我不知道这个页面变化是去工作。如果它的工作,你可能需要等待第二deviceready事件。

It looks to me that you have a local web page (with the cordova script included) and from there you change to the remote page (that also includes the script). I'm not sure this page change is going to work. If it worked, you might have to wait for the second deviceready event.

但你可以设置远程站点页面的科尔多瓦应用程序的根页面,无需中间加载器页面。只需设置它在config.xml文件中:

But you can just set the remote site page as the root page in the cordova app, no need for an intermediate "loader" page. Just set it in the config.xml file:

<content src="http://your.website.fake/index.html" />

您需要确保您允许的应用程序加载您的网站。在这同一个文件,你应该增加:

You need to make sure that you allow loading your site in the app. In this same file, you should add:

<access origin="http://your.website.fake" subdomains="true"/> 

这篇关于如何从远程页面访问到PhoneGap的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆