Phonegap - access to api from external website

試著忘記壹切 提交于 2019-12-11 01:15:09

问题


I set in config files:

<access origin="*" subdomains="true" />
<access origin=".*" subdomains="true" />
<content src="http://mydomain.pl/aps_mobile/" />

But on http://mydomain.pl/aps_mobile/ don't execute event "deviceready" and navigator.camera is undefined. What i doing wrong?


回答1:


You don't access to hardware resource if you execute the cordova script from a external host because the script is not mapped to libs/cordova.x.x.x.jar of Phonegap application. But you can resolve in this way:

in res/xml/config.xml

<access origin="*" />
<content src="index.html" />

in assets/www/index.html

<body>
    <script type="text/javascript" src="cordova-x.x.x.js"></script>
    <iframe name="framewrap" id="framewrap"
        style="border:0;position: absolute; top: 0; left: 0;width: 100%;"
        src="http://yourwebsite.pl">
    </iframe>
    <script type="text/javascript"> 
        document.getElementById("framewrap").contentWindow.navigator = navigator;
    </script>
 </body>

finaly, in camera configuration, you must set destinationType to 0 if you wanto DATA_URL, 1 if you want FILE_URI or 2 if you want NATIVE_URI.

I hope to help you




回答2:


Index file shouldn't be on server. You need yo have an index.html in your assets folder of the app, and make the connection to the server through jquery ajax calls. Also make sure you have imported cordova and phonegap javascript files in index.html



来源:https://stackoverflow.com/questions/16064142/phonegap-access-to-api-from-external-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!