Using PhoneGap and keeping the UI on the server

微笑、不失礼 提交于 2019-12-22 10:26:55

问题


I'm continuing my research on solutions for our organization for our mobile app strategy. There's two somewhat conflicting requirements:

  • it should be a web app in that all updates for users are immediate as we update the app on the server

  • the app should leverage native UI widgets and native device features as much as possible

With PhoneGap, the process appears to be that you'd normally keep the UI on the device, as part of the compiled app, and you'd hit your server via AJAX to deal with the data updates and submissions. That then gives you access to the native device's UI widgets and features using the PhoneGap API into their hooks.

However, in doing that, we lose bullet point one.

My question is if one can, using PhoneGap, create a 'web view' within the app that would allow us to keep the UI on our server (the app then pretty much becomes a custom browser). And, if so, could our UI still access the device's native functionality via PhoneGap's API or is that only accessible if we compiled our UI code?


回答1:


A similar question came up on the PhoneGap Google Group recently.
One thing that came up was that you are unlikely to pass app store certification if you are loading UI and core functionality from a remote server as this invalidates much of the purpose of certification.




回答2:


If you're going to do this, you should set up web services that return the content you want to display to users. Then you can use jQuery Mobile and PhoneGap to take the content returned from the server and display it on the application with the appropriate native UI widgets and features that you want.

So use jQuery Mobile to hit your server for data using something like:

var fileUrl = "http://www.mywebserver.com/servedevice?data=current&selection=fresh";
$.ajax({
    url: fileUrl,
    dataType: "html",
    success: function( html ) {
        // If the call succeeds, do something with the return value here
    }
});

There are many other ways you can handle it including JSONP methods. See the documentation for details: http://api.jquery.com/jQuery.ajax/




回答3:


Another approach would be to point your HTML file at a server for the JavaScript, just like a CDN file load. Then, your app's JavaScript would be loaded at runtime instead of bundled into the app. However, when it actually runs, it is running within the PhoneGap WebView so it has access to all of the PhoneGap APIs.

This is the jQuery Mobile example:

<script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>


来源:https://stackoverflow.com/questions/6254009/using-phonegap-and-keeping-the-ui-on-the-server

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