我是一名网络开发人员,我想把我的网络产品搬到iPhone上。其中一个产品就像谷歌Maps:在手机屏幕上显示地图,您可以拖动或调整地图的大小,并查看我们添加到地图的一些信息。
我知道有一些技术可以让你使用HTML、CSS和Javascript来开发原生iPhone应用。我列举了一些:
Ansca移动 PhoneGap Appcelerator
还有其他类似的产品吗?它们之间有什么区别?我该选哪一个呢?
我是一名网络开发人员,我想把我的网络产品搬到iPhone上。其中一个产品就像谷歌Maps:在手机屏幕上显示地图,您可以拖动或调整地图的大小,并查看我们添加到地图的一些信息。
我知道有一些技术可以让你使用HTML、CSS和Javascript来开发原生iPhone应用。我列举了一些:
Ansca移动 PhoneGap Appcelerator
还有其他类似的产品吗?它们之间有什么区别?我该选哪一个呢?
当前回答
我在stackoverflow上注册只是为了评论上面投票最多的答案。糟糕的是,stackoverflow不允许新成员发表评论。所以我必须让这个评论看起来更像一个答案。
Rory Blyth的回答包含了关于这两个javascript移动框架的一些有效观点。然而,他的关键点是不正确的。事实是,Titanium和PhoneGap大同小异。它们都通过一组javascript api公开手机功能,应用程序的逻辑(html, css, javascript)在原生WebView控件中运行。
PhoneGap is not just a native wrapper of a web app. Through the PhoneGap javascript APIs, the "web app" has access to the mobile phone functions such as Geolocation, Accelerometer Camera, Contacts, Database, File system, etc. Basically any function that the mobile phone SDK provides can be "bridged" to the javascript world. On the other hand, a normal web app that runs on the mobile web browser does not have access to most of these functions (security being the primary reason). Therefore, a PhoneGap app is more of a mobile app than a web app. You can certainly use PhoneGap to wrap a web app that does not use any PhoneGap APIs at all, but that is not what PhoneGap was created for. Titanium does NOT compile your html, css or javascript code into "native bits". They are packaged as resources to the executable bundle, much like an embedded image file. When the application runs, these resources are loaded into a UIWebView control and run there (as javascript, not native bits, of course). There is no such thing as a javascript-to-native-code (or to-objective-c) compiler. This is done the same way in PhoneGap as well. From architectural standpoint, these two frameworks are very similar.
Now, are they any different? Yes. First, Titanium appears to be more feature rich than PhoneGap by bridging more mobile phone functions to javascript. Most noticeably, PhoneGap does not expose many (if any) native UI components to javascript. Titanium, on the other hand, has a comprehensive UI APIs that can be called in javascript to create and control all kinds of native UI controls. Utilizaing these UI APIs, a Titanium app can look more "native" than a PhoneGap app. Second, PhoneGap supports more mobile phone platforms than Titanium does. PhoneGap APIs are more generic and can be used on different platforms such as iPhone, Android, Blackberry, Symbian, etc. Titanium is primarily targeting iPhone and Android at least for now. Some of its APIs are platform specific (like the iPhone UI APIs). The use of these APIs will reduce the cross-platform capability of your application.
所以,如果你想让你的应用看起来更“原生”,Titanium是一个更好的选择。如果你想更容易地将你的应用“移植”到另一个平台,PhoneGap会更好。
更新8/13/2010: 链接到一名钛员工对米奇问题的回答。
更新12/04/2010: 我决定给这篇文章一个年度审查,以保持其信息的最新。许多事情在一年中发生了变化,使得最初的帖子中的一些信息过时了。
最大的变化来自钛金属。今年早些时候,Appcelerator发布了Titanium 1.0,从架构的角度来看,它与之前的版本有很大的不同。在1.0中,UIWebView控件不再使用。相反,您可以为任何UI函数调用Titanium api。这一变化意味着以下几点:
Your app UI becomes completely native. There is no more web UI in your app since the native Titanium APIs take over control of all your UI needs. Titanium deserves a lot of credit by pioneering on the "Cross-Platform Native UI" frontier. It gives programmers who prefer the look and feel of native UI but dislike the official programming language an alternative. You won't be able to use HTML or CSS in your app, as the web view is gone. (Note: you can still create web view in Titanium. But there are few Titanium features that you can take advantage of in the web view.)Titanium Q&A: What happened to HTML & CSS? You won't be able to use popular JS libraries such as JQuery that assume the existence of an DOM object. You continue to use JavaScript as your coding language. But that is pretty much the only web technology you can utilize if you come to Titanium 1.0 as a web programmer.
钛视频:钛1.0有什么新功能。
现在,Titanium 1.0会把你的JavaScript编译成“原生位”吗?不。Appcelerator终于在这个开发者博客上澄清了这个问题:Titanium Guides Project: JS Environment。我们程序员比市场部的人更真诚,不是吗?:-)
接下来是PhoneGap。关于PhoneGap没有太多新东西可说。我的看法是,PhoneGap的开发在IBM今年晚些时候加入之前并不活跃。有些人甚至认为IBM为PhoneGap贡献的代码比Nitobi还多。不管这是不是真的,PhoneGap正在积极开发中,这是很好的。
PhoneGap继续以网页技术为基础,即HTML, CSS和JavaScript。PhoneGap似乎不打算像Titanium那样将原生UI功能与JavaScript连接起来。虽然Web UI在性能和原生外观上仍落后于原生UI,但这种差距正在迅速缩小。在web技术中,有两个趋势可以确保移动web UI在性能方面的亮点:
JavaScript引擎从解释器转移到虚拟机。JavaScript是JIT编译成本地代码,以便更快地执行。Safari JS引擎:SquirrelFish Extreme 网页渲染从依赖CPU转向使用GPU加速。在硬件加速的帮助下,页面转换和3D动画等图形密集型任务变得更加流畅。GPU加速合成Chrome
Such improvements that are originated from desktop browsers are being delivered to mobile browsers quickly. In fact, since iOS 3.2 and Android 2.0, the mobile web view control has become much more performing and HTML5 friendly. The future of mobile web is so promising that it has attracted a big kid to town: JQuery has recently announced its mobile web framework. With JQuery Mobile providing UI gadgets, and PhoneGap providing phone features, they two combined creates a perfect mobile web platform in my opinion.
我还应该提到Sencha Touch作为另一个移动web UI小工具框架。Sencha Touch 1.0版本最近发布,采用了包括GPLv3在内的双重授权模式。Sencha Touch可以很好地与PhoneGap合作,就像JQuery Mobile一样。
如果你是一个GWT程序员(像我一样),你可能想看看GWT Mobile,这是一个使用GWT创建移动web应用程序的开源项目。它包括一个PhoneGap GWT包装器,允许在GWT中使用PhoneGap。
其他回答
我在stackoverflow上注册只是为了评论上面投票最多的答案。糟糕的是,stackoverflow不允许新成员发表评论。所以我必须让这个评论看起来更像一个答案。
Rory Blyth的回答包含了关于这两个javascript移动框架的一些有效观点。然而,他的关键点是不正确的。事实是,Titanium和PhoneGap大同小异。它们都通过一组javascript api公开手机功能,应用程序的逻辑(html, css, javascript)在原生WebView控件中运行。
PhoneGap is not just a native wrapper of a web app. Through the PhoneGap javascript APIs, the "web app" has access to the mobile phone functions such as Geolocation, Accelerometer Camera, Contacts, Database, File system, etc. Basically any function that the mobile phone SDK provides can be "bridged" to the javascript world. On the other hand, a normal web app that runs on the mobile web browser does not have access to most of these functions (security being the primary reason). Therefore, a PhoneGap app is more of a mobile app than a web app. You can certainly use PhoneGap to wrap a web app that does not use any PhoneGap APIs at all, but that is not what PhoneGap was created for. Titanium does NOT compile your html, css or javascript code into "native bits". They are packaged as resources to the executable bundle, much like an embedded image file. When the application runs, these resources are loaded into a UIWebView control and run there (as javascript, not native bits, of course). There is no such thing as a javascript-to-native-code (or to-objective-c) compiler. This is done the same way in PhoneGap as well. From architectural standpoint, these two frameworks are very similar.
Now, are they any different? Yes. First, Titanium appears to be more feature rich than PhoneGap by bridging more mobile phone functions to javascript. Most noticeably, PhoneGap does not expose many (if any) native UI components to javascript. Titanium, on the other hand, has a comprehensive UI APIs that can be called in javascript to create and control all kinds of native UI controls. Utilizaing these UI APIs, a Titanium app can look more "native" than a PhoneGap app. Second, PhoneGap supports more mobile phone platforms than Titanium does. PhoneGap APIs are more generic and can be used on different platforms such as iPhone, Android, Blackberry, Symbian, etc. Titanium is primarily targeting iPhone and Android at least for now. Some of its APIs are platform specific (like the iPhone UI APIs). The use of these APIs will reduce the cross-platform capability of your application.
所以,如果你想让你的应用看起来更“原生”,Titanium是一个更好的选择。如果你想更容易地将你的应用“移植”到另一个平台,PhoneGap会更好。
更新8/13/2010: 链接到一名钛员工对米奇问题的回答。
更新12/04/2010: 我决定给这篇文章一个年度审查,以保持其信息的最新。许多事情在一年中发生了变化,使得最初的帖子中的一些信息过时了。
最大的变化来自钛金属。今年早些时候,Appcelerator发布了Titanium 1.0,从架构的角度来看,它与之前的版本有很大的不同。在1.0中,UIWebView控件不再使用。相反,您可以为任何UI函数调用Titanium api。这一变化意味着以下几点:
Your app UI becomes completely native. There is no more web UI in your app since the native Titanium APIs take over control of all your UI needs. Titanium deserves a lot of credit by pioneering on the "Cross-Platform Native UI" frontier. It gives programmers who prefer the look and feel of native UI but dislike the official programming language an alternative. You won't be able to use HTML or CSS in your app, as the web view is gone. (Note: you can still create web view in Titanium. But there are few Titanium features that you can take advantage of in the web view.)Titanium Q&A: What happened to HTML & CSS? You won't be able to use popular JS libraries such as JQuery that assume the existence of an DOM object. You continue to use JavaScript as your coding language. But that is pretty much the only web technology you can utilize if you come to Titanium 1.0 as a web programmer.
钛视频:钛1.0有什么新功能。
现在,Titanium 1.0会把你的JavaScript编译成“原生位”吗?不。Appcelerator终于在这个开发者博客上澄清了这个问题:Titanium Guides Project: JS Environment。我们程序员比市场部的人更真诚,不是吗?:-)
接下来是PhoneGap。关于PhoneGap没有太多新东西可说。我的看法是,PhoneGap的开发在IBM今年晚些时候加入之前并不活跃。有些人甚至认为IBM为PhoneGap贡献的代码比Nitobi还多。不管这是不是真的,PhoneGap正在积极开发中,这是很好的。
PhoneGap继续以网页技术为基础,即HTML, CSS和JavaScript。PhoneGap似乎不打算像Titanium那样将原生UI功能与JavaScript连接起来。虽然Web UI在性能和原生外观上仍落后于原生UI,但这种差距正在迅速缩小。在web技术中,有两个趋势可以确保移动web UI在性能方面的亮点:
JavaScript引擎从解释器转移到虚拟机。JavaScript是JIT编译成本地代码,以便更快地执行。Safari JS引擎:SquirrelFish Extreme 网页渲染从依赖CPU转向使用GPU加速。在硬件加速的帮助下,页面转换和3D动画等图形密集型任务变得更加流畅。GPU加速合成Chrome
Such improvements that are originated from desktop browsers are being delivered to mobile browsers quickly. In fact, since iOS 3.2 and Android 2.0, the mobile web view control has become much more performing and HTML5 friendly. The future of mobile web is so promising that it has attracted a big kid to town: JQuery has recently announced its mobile web framework. With JQuery Mobile providing UI gadgets, and PhoneGap providing phone features, they two combined creates a perfect mobile web platform in my opinion.
我还应该提到Sencha Touch作为另一个移动web UI小工具框架。Sencha Touch 1.0版本最近发布,采用了包括GPLv3在内的双重授权模式。Sencha Touch可以很好地与PhoneGap合作,就像JQuery Mobile一样。
如果你是一个GWT程序员(像我一样),你可能想看看GWT Mobile,这是一个使用GWT创建移动web应用程序的开源项目。它包括一个PhoneGap GWT包装器,允许在GWT中使用PhoneGap。
我对PhoneGap的理解是他们为很多iPhone api提供Javascript api。
对于有web开发背景的人来说,Titanium似乎更容易一些。它是一个简单的XML文件,用于创建一个基本的TabView应用程序,然后内容区域中的所有内容都由HTML / JS控制。我也知道Titanium确实为一些框架提供了一些javascript访问(特别是访问位置信息、电话ID等)。
更新:Titanium在0.8版本的框架中添加了Maps API。
据我所知,这两者之间有一些不同之处:
PhoneGap basically generates native wrappers for what are still web apps. It spits out a WhateverYourPlatformIs project, you build it, and deploy. If we're talking about the iPhone (which is where I spend my time), it doesn't seem much different from creating a web app launcher (a shortcut that gets its own Springboard icon, so you can launch it like (like) a native app). The "app" itself is still html/js/etc., and runs inside a hosted browser control. What PhoneGap provides beyond that is a bridge between JavaScript and native device APIs. So, you write JavaScript against PhoneGap APIs, and PhoneGap then makes the appropriate corresponding native call. In that respect, it is different from deploying a plain old web app. Titanium source gets compiled down to native bits. That is, your html/js/etc. aren't simply attached to a project and then hosted inside a web browser control - they're turned into native apps. That means, for example, that your app's interface will be composed of native UI components. There are ways of getting native look-and-feel without having a native app, but... well... what a nightmare that usually turns out to be.
两者的相似之处在于,您可以使用典型的web技术(html/js/css/等等等等)编写所有内容,并且您可以通过自定义JavaScript api访问本机功能。
但是,同样,PhoneGap应用程序(PhonGapps?我不知道……这名字蠢吗?说起来容易些——我知道这么多)以网络应用开始他们的生活,以网络应用结束他们的生活。在iPhone上,html/js/等等。只是在UIWebView控件中执行,PhoneGap JavaScript api你的js调用被路由到本地api。
钛应用变成了原生应用——它们只是使用web开发技术开发的。
这到底是什么意思呢?
Titanium应用看起来就像一个“真正的”应用,因为归根结底,它就是一个“真正的”应用。 PhoneGap应用程序看起来像一个托管在浏览器控件中的web应用程序,因为归根结底,它是一个托管在浏览器控件中的web应用程序。
哪一种适合你?
如果你想使用web开发技能编写本地应用程序,Titanium是你最好的选择。 如果你想要使用web开发技能编写一个应用程序,你可以实际部署到多个平台(iPhone、Android、黑莓和其他他们决定包括的平台),如果你想通过统一的JavaScript API访问本机平台功能的子集(GPS、加速计等),PhoneGap可能是你想要的。
你可能会问:为什么我要写一个PhoneGapp(我决定使用这个名字),而不是一个托管在网络上的web应用程序?我是否仍然可以通过这种方式访问一些原生设备功能,同时也拥有真正的web部署的便利,而不是强迫用户下载我的“原生”应用并安装它?
答案是:因为你可以将你的PhoneGapp提交到App Store并收费。你还会看到启动器图标,这让用户更难忘记你的应用(比起应用图标,我更容易忘记书签)。
You could certainly charge for access to your web-hosted web app, but how many people are really going to go through the process to do that? With the App Store, I pick an app, tap the "Buy" button, enter a password, and I'm done. It installs. Seconds later, I'm using it. If I had to use someone else's one-off mobile web transaction interface, which likely means having to tap out my name, address, phone number, CC number, and other things I don't want to tap out, I almost certainly wouldn't go through with it. Also, I trust Apple - I'm confident Steve Jobs isn't going to log my info and then charge a bunch of naughty magazine subscriptions to my CC for kicks.
不管怎样,除了涉及到web开发技术之外,PhoneGap和Titanium是非常不同的——只有表面上的可比。
I hate web apps, by the by, and if you read iTunes App Store reviews, users are pretty good at spotting them. I won't name any names, but I have a couple "apps" on my phone that look and run like garbage, and it's because they're web apps that are hosted inside UIWebView instances. If I wanted to use a web app, I'd open Safari and, you know, navigate to one. I bought an iPhone because I want things that are iPhone-y. I have no problem using, say, a snazzy Google web app inside Safari, but I'd feel cheated if Google just snuck a bookmark onto Springboard by presenting a web app as a native one.
我得走了。我女朋友脸上有一种"拜托你别再用电脑三秒钟"的表情。
以下是对Appcelerator和PhoneGap的最新深入分析:http://savagelook.com/blog/portfolio/a-deeper-look-at-appcelerator-and-phonegap
这里有更多关于它们在编程上如何不同的细节: http://savagelook.com/blog/portfolio/phonegap-is-web-based-appcelerator-is-pure-javascript
你应该学习objective - c和编程原生应用程序。不要依赖这些你以为会让生活更容易的东西。苹果确保最简单的方法就是使用他们的本地工具和语言。对于你的100行javascript,我可以在3行代码中做同样的事情,或者完全不需要代码,这取决于元素。看一些教程——如果你理解javascript,那么objective - c并不难。变通办法很糟糕,苹果可以随时把你的插头拔掉。