简体   繁体   English

将Ruby on Rails应用程序转换为本地Android PhoneGap应用程序

[英]Convert Ruby on Rails app to native Android PhoneGap app

I've been working on a jQuery mobile web app written in Ruby on Rails, and would like to make it available as a native Android app. 我一直在研究用Ruby on Rails编写的jQuery移动Web应用程序,并希望将其作为本机Android应用程序提供。 I've setup the phonegap project to load my url, and everything seems to be working, but I've been reading that Google will reject the app if it's simply a webview container to an external url. 我已经设置了phonegap项目来加载我的网址,并且一切似乎都可以正常运行,但是我一直在读,如果它只是外部URL的Webview容器,则Google会拒绝该应用。 Has anyone had any experience with this? 有没有人有这方面的经验?

From what I can tell, I'll need to rewrite the web app to use ajax calls to populate the page, as opposed to relying solely on web requests to my web server. 据我所知,我将需要重写Web应用程序以使用Ajax调用来填充页面,而不是仅依赖于对Web服务器的Web请求。 Can anyone offer any insight into this? 谁能对此提供任何见解? Would they accept a PhoneGap app that simply loads an external url? 他们会接受仅加载外部URL的PhoneGap应用吗? Any help is appreciated. 任何帮助表示赞赏。

Update1: I've also read that being able to handle no internet connection is one of the main reasons they will approve/reject your app. Update1:我还读到无法处理互联网连接是他们批准/拒绝您的应用程序的主要原因之一。 I think this could be handled in the android app with some logic that checks for an internet connection, and if it exists, load the external url, if it doesn't load a local html splash page. 我认为可以在android应用中使用某种逻辑来处理此问题,该逻辑检查互联网连接,如果存在,则加载外部url,如果它不加载本地html启动页面。 Would this idea be ok? 这个想法可以吗?

Update2: Would it be an option to have a "skeleton" of the app as basic html files within the phone gap app, which just uses ajax to pull down all of the main html? Update2:是否可以选择将应用程序的“骨骼”作为基本的html文件包含在手机差距应用程序中,而该应用程序仅使用ajax下拉所有主要的html? That way the app would still function without an internet connection, but you could also make large changes to the content of the pages which would be pulled down in every request. 这样,该应用程序仍然可以在没有互联网连接的情况下运行,但是您还可以对页面的内容进行较大的更改,这些内容将在每个请求中都被下拉。 Is that a viable option? 那是可行的选择吗?

I've never heard of an app being rejected from the Play Store due to just being a WebView container. 我从未听说过某个应用只是因为是WebView容器而被Play商店拒绝了。 But even if they wont reject your app for this, you shouldn't be building a PhoneGap application this way. 但是,即使他们不会为此拒绝您的应用程序,您也不应该以这种方式构建PhoneGap应用程序。 You'll end up with an app that will feel like it's just a WebView container, and an app that breaks easily when connectivity gets spotty. 您最终会得到一个感觉像只是WebView容器的应用程序,并且当连接变得混乱时,该应用程序很容易损坏。 Remember that even in good reception, latency on a phone is high, so reducing the number of requests you have to make (for static files and assets) is paramount. 请记住,即使在良好的接收状态下,电话的延迟也很高,因此减少您必须发出的请求数量(对于静态文件和资产)至关重要。

Ideally, when porting a web site to a PhoneGap application, you should be decoupling your interface as much as possible. 理想情况下,在将网站移植到PhoneGap应用程序时,应尽可能取消界面的耦合。 Fewer variables should be passed down from the controller to the views, and more data should pass through AJAX calls. 较少的变量应从控制器向下传递到视图,并且更多的数据应通过AJAX调用传递。 When your front end code (all of the files in app/views) can be served statically, moving to a PhoneGap app is easy. 当您的前端代码(应用程序/视图中的所有文件)可以静态提供时,转移到PhoneGap应用程序很容易。

Ensure that the actions in your controllers all have responses for JS ( format.js ), not just HTML. 确保控制器中的所有动作都具有对JS( format.js )的响应,而不仅仅是HTML。 Your views should be making AJAX calls to rails to get the data that fills in pages via AJAX. 您的视图应该正在对Rails进行AJAX调用,以获取通过AJAX填充页面的数据。 Then you can bundle your views (and your assets) into your PhoneGap app. 然后,您可以将视图(和资产)捆绑到PhoneGap应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM