游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

HTML与原生应用合体或成开发者第三选择

发布时间:2011-07-16 16:43:18 Tags:,,

作者:Ron Perry

今天似乎人人都已陷入HTML5与原生手机应用非此即彼的论战中,并极力鼓吹其中一方的发展潜力。虽然苹果和谷歌已经各自偏向一方,但有些公司却已经做出第三种选择——将这两者结为一体的“混合应用”。

混合应用开发过程采纳了原生应用功能,同时也融合了更具前瞻性的HTML5技术。

混合应用是一种需要下载,但有部分或者所有用户面植入了浏览器元素的应用程序。对用户来说,混合应用与原生应用并无二致——它们都需要通过应用商店渠道下载,都可以保存的在手机,运行方式与原生应用并无差别。但对开发者来说,这其中的差异却不容忽视,因为这意味着他们无需针对各个手机操作系统重新编写应用,而是可以选择用HTML、CSS和JavaScript编写其中一部分代码,并在多个平台上运行应用程序。

hybrid apps(from venturebeat)

hybrid apps(from venturebeat)

“混合”这一词实际上道出了这种应用的多种可能性。例如美国银行、Facebook和Yelp的iPhone应用程序,就有部分内容是直接将公司网站的部分页面转移过来。而像《Tower Madness》游戏等其他应用,则嵌入了一些以HTML5编写的页面。但还有一些应用,例如Harmounius(一款绘图画板)或Logitec’s Squeezebox Controller的UI则完全采用HTML技术。

从商业角度来看,尽早采用HTML5技术是最明智的做法。有些行业巨头已经将HTML当作唯一可行的跨平台开发技术。传说中的Facebook项目“Project Spartan”(游戏邦注:有人称它是一个基于HTML5的网页应用商店),以及微软宣布开发者将可使用HTML5和JavaScript为Windows 8编写应用程序等消息,更增加了HTML5获胜的筹码。甚至有人认为现在的开发商面临的并非“是否”,而是“何时”采纳HTML技术的问题。

有些公司并不急于追赶HTML5潮流的一个主要原因是,他们对HTML5应用无法接入移动设备原始相关功能的这一情况颇有顾虑。纯粹的移动网页应用(游戏邦注:这里指那些运行于浏览器的应用,而非混合应用)目前还不能访问摄像头、麦克风、通讯录等手机功能。虽然W3C已经启动支持网页应用访问这类移动设备功能的项目,但移动浏览器现在还不具备这些功能已是不争的事实,而这一点却是许多创新型手机应用的必备条件。

但在混合应用领域,PhoneGap库等开源框架却可以让JavaScript代码访问手机的罗盘、照相等功能成为可能,甚至可以搜索或创建联系人列表、约会安排等其他多种网页应用无法接入的手机功能。

接入移动设备功能并非混合应用与移动网页应用的唯一区别。这两者之间的另一大差异表现在,混合应用多数需通过应用商店渠道下载,而不是在浏览器运行,用户需要下载安装才行。

另外,混合应用的HTML页面可通过网络服务器传送,但这一点并非必备条件。如果要提高运行性能,混合应用还可以植入一个包含其所需的网页资源(例如HTML、JavaScript、CSS和图像)的副本,以便用户快速访问内容,而不必等待网络服务器将内容传送过来。

除此之外,混合应用的另一个特点在于,它与网页应用又有共通之处。混合应用并不像原生应用那样,直接使用手机操作系统所支持的图像API和UI,其多数页面采用的是浏览器的渲染引擎,这与网页应用一致。这就意味着从当前来看,只有原始编写页面才可以实现像游戏一般高质量的图像效果,不过这一点与商务型应用的关系倒不大。现在我们还无法在手机平台看到以HTML编写的《真人快打3》。

庆幸的是,目前主流智能手机和平板电脑都有强大的HTML渲染引擎,它们已经可以支持多数即将到来的HTML5和CSS3技术标准。

Sencha Touch、jQuery Mobile和dojox.mobile等JavaScript工具包完全可与混合应用开发模型兼容,使这类应用从外观和感觉与原生应用不分彼此。由此可见,在现代手机硬件设备上运行的混合应用,可以使用HTML5、CSS3和JavaScript实现高度的交互性,创建出色的用户界面。

如果你无法使用HTML满足特定图像或交互性需求,不妨选择结合网页和原生应用功能的混合应用。混合应用中的有趣典型之一就是韩国信用卡Lotte,其应用程序有100个页面以HTML编写而成,仅用一小部分采用了增强现实感功能的原始页面。

还有不少公司在打算转向HTML5网页应用的同时,也正在开发混合应用。从战略性角度来看,开发公司需认真考虑是否尽早采用HTML开发手机应用。混合应用模式虽然并不适用于所有的应用开发,但至少为大量的可下载应用提供了一个划算的解决方案,也可以算是开发者逐渐向HTML5领域演变的一种铺垫。(本文为游戏邦/gamerboom.com编译,如需转载请联系:游戏邦

Hybrid mobile apps take off as HTML5 vs. native debate continues

Ron Perry

Everyone seems to be gung-ho about HTML5 or native mobile apps, and religiously preaching for one approach over the other. Yet, while mobile giants such as Apple and Google battle it out, some companies are already opting for a third option — mediating the two approaches in what is popularly known as the “hybrid app approach”.

Hybrid app development employs native capabilities while also serving as a strategic stepping stone towards adoption of HTML5.

A hybrid app is a native, downloadable app, that runs all or some of its user interface in an embedded browser component. To the user, a hybrid app is almost indistinguishable from a native one: it is downloaded from the app store or marketplace, it is stored on the device, and it is launched just like any other app. But to developers there is a huge difference, because instead of rewriting the app from scratch for each mobile OS, they write at least some of their application code in HTML, CSS and JavaScript, and reuse it across devices.

The term “hybrid” actually spans a wide range of possibilities. Some apps, like the Bank of America, Facebook and Yelp iPhone apps, simply load some pages from their web site as part of the app. Other apps, like the Tower Madness game, include a few embedded pages that are written in HTML. But there are other apps, like Harmonius (a graphical sketchpad) or Logitec’s Squeezebox Controller that have their entire UI implemented in HTML.

From a business perspective, it makes a lot of sense to adopt HTML5 as early as possible. Industry heavyweights have pointed to HTML as the only viable cross-platform technology. Add the rumors about Facebook’s “Project Spartan” (believed to be an app store for HTML5-based mobile web apps), and Microsoft’s announcement that developers will be able to use HTML5 and JavaScript to create applications for the touch-friendly Windows 8, and it almost becomes just a question of “when” companies will adopt HTML for app development rather than “if”.

A primary reason that many companies are not already jumping on the HTML5 bandwagon is the belief that HTML apps cannot access native device features. Indeed, pure mobile web apps (i.e., those that run in the browser – not hybrid ones) are currently restricted in their access to features such as the camera, microphone, address book, and so forth. And while there is work in progress at the W3C to allow web apps to access such device services, mobile browsers do not currently provide such functionality – a key requirement for many innovative mobile apps.

But in the world of hybrid apps, frameworks such as the open source PhoneGap library make it possible for JavaScript code to query the compass, take pictures, find or create contacts and appointments, and tap many other device features that mobile web apps are barred from accessing.

Access to device features is not the only difference between hybrid apps and mobile web apps. Another important difference is that hybrid apps are mostly distributed through app stores: You don’t browse to a hybrid app – you download and install it.

Also, HTML pages of a hybrid app can be transmitted by a web server, but that’s not a requirement. To improve performance, hybrid apps can include a bundled copy of all required web resources (i.e., HTML, JavaScript, CSS and images) so that users will get instant access to them, without having to wait for a web server to send them over.

Differences aside, hybrid apps share some traits with mobile web apps. Unlike pure native apps, which make direct use of the graphics APIs and UI services provided by the operating system, in hybrid apps, most pages are executed by the rendering engine of a browser – much like they are in web apps. This means that, currently, only natively coded pages can achieve game-quality graphics, and although this is less relevant for business apps, you probably won’t be seeing the likes of Ultimate Mortal Kombat 3 written in HTML for mobile devices anytime soon.

Fortunately, the leading smartphones and tablets have very powerful HTML rendering engines, which already support most of the upcoming HTML5 and CSS3 standards.

JavaScript toolkits like Sencha Touch, jQuery Mobile and dojox.mobile are fully compatible with the hybrid app development model, making it easier to achieve a look and feel that is often indistinguishable from native. As a result, hybrid apps running on mobile devices with reasonably modern hardware can achieve highly interactive and impressive user interfaces using just HTML5, CSS3 and JavaScript.

For those cases where your app does require special graphics or system-level interaction that cannot be achieved with HTML, hybrid apps can combine web pages with native ones. One interesting hybrid example is an app by Korean credit card Lotte (pictured below), which has 100 pages written in HTML (reused between Android and iPhone), along with a small number of native pages that implement an augmented reality feature.

Other organizations are developing hybrid apps, while planning to turn them into HTML5 web apps in the future without having to rewrite them from scratch.

From a strategic point of view, development organizations should seriously consider adopting HTML for mobile app development sooner rather than later. The hybrid app model, although not suitable for all app development needs, provides a cost-effective solution for a very wide range of downloadable app types and allows gradual entry into the new world of HTML5 while future-proofing your investment.(source:venturebeat


上一篇:

下一篇: