我是一名网络开发人员,我想把我的网络产品搬到iPhone上。其中一个产品就像谷歌Maps:在手机屏幕上显示地图,您可以拖动或调整地图的大小,并查看我们添加到地图的一些信息。
我知道有一些技术可以让你使用HTML、CSS和Javascript来开发原生iPhone应用。我列举了一些:
Ansca移动 PhoneGap Appcelerator
还有其他类似的产品吗?它们之间有什么区别?我该选哪一个呢?
我是一名网络开发人员,我想把我的网络产品搬到iPhone上。其中一个产品就像谷歌Maps:在手机屏幕上显示地图,您可以拖动或调整地图的大小,并查看我们添加到地图的一些信息。
我知道有一些技术可以让你使用HTML、CSS和Javascript来开发原生iPhone应用。我列举了一些:
Ansca移动 PhoneGap Appcelerator
还有其他类似的产品吗?它们之间有什么区别?我该选哪一个呢?
当前回答
让HTML5的小部件看起来像iphone的小部件是一回事,但让它们表现得同样出色完全是另一回事。html5动画的性能(甚至是简单的视图转换),滚动长列表,对手势的响应感觉很粘和不稳定。iPhone用户会注意到其中的区别。
不同设备所支持的手势类型也存在一些差异,这也会导致特定平台的代码和可用性问题。
我想我还是会继续使用原生应用。
其他回答
我在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。
Titanium支持native mapkit
让HTML5的小部件看起来像iphone的小部件是一回事,但让它们表现得同样出色完全是另一回事。html5动画的性能(甚至是简单的视图转换),滚动长列表,对手势的响应感觉很粘和不稳定。iPhone用户会注意到其中的区别。
不同设备所支持的手势类型也存在一些差异,这也会导致特定平台的代码和可用性问题。
我想我还是会继续使用原生应用。
我参加了一门关于Android/iPhone开发的课程,我们花了8周时间在Titanium上(游戏邦注:版本是Titanium 1.4.2,时间是2010年11月左右)。以下是我的经验。
iPhone Android双重目标
尽管API指南声称该功能在Android和iPhone上都可用,但事实并非如此。很多东西根本无法在某个平台上运行。有些事情是不同的。
A lot of the people in the class has done iPhone applications, and they can not make them work on Android without major rewrites. I developed a simple childrens app called Animap (see android market / Appstore in Sweden) and started developing under Windows. Once the Android target was working I opened the project on OS X. It does not show any build stuff for iPhone, just for Android. You need to start a dual target project under OS X. (Ok, I copied the relevant files to a new project). Next problem - the animations does not work on iPhone (they work on Android). The scrolling events does not work the same on the iPhone. (i.e on Android you get the untouch event when user stops scrolling and releases their finger from the screen, this does not happen on the iPhone).
因为在某些地方没有提到这一点,所以基本上需要先在一个平台上进行试错编程,然后再在另一个平台上进行试错编程。我的意思是,让像Animap这样简单的应用在另一个平台上运行需要大约两天的时间。你还需要有if (android) then…或者(iphone)…在你的代码中…
下载和设置
You must follow the instructions to the letter. Do not try to use java 64 bit. It will not compile the KitchenSink 1.4.0 demo application. (1.3 works OK!) You must put files directly on the C drive as long pathnames will make the external program not receiving all command line parameters if they get to long. (Fine for small programs though) 1/3 of the times, the toolchain simply stops and you must press 'launch' again. Then it will probably work... very unreliable. The simulator will not be found on startup and then you must simply kill of adb.exe with Ctrl+Alt+Delete and retry.
网络连接
在wi - fi网络上,有时会断开实时连接,Titanium会崩溃(编译/部署接口) 如果你没有工作的互联网连接,它将无法启动,因为它不能登录到他们的服务器。
API
与此相比,CSS, HTML和jQuery是一件轻松的事情。Titanium类似于任何其他旧的GUI API,你需要为每个按钮/字段等设置一些属性。得到一个错误的字段只是很容易,记住所有需要设置的属性?你在正确的地方用大写字母拼写了吗?(因为这不会被编译器捕获,但如果你幸运地测试了这部分,将被视为运行时错误)
在Titanium中,当你在控件上添加另一个视图或单击GUI中的其他地方时,事情就会简单地中断。
文档
有几个API页面带有Android符号,但只会在您尝试创建控件时返回null。尽管有这些符号,但它们并不只是在Android平台上可用。有时Android被提到不支持某个特定的方法,但整个API就缺失了。
KitchenSink并
演示应用程序。我是否提到过,如果您将它放在Eclipse项目文件夹中,因为路径太长而无法编译?必须放在C盘的根文件夹里。我目前使用的符号链接(mklink /J…)
无证的方法
你必须合理地使用事物作为标签。setText('Hello World')来更改一个可靠的标签,但这根本没有记录。
调试
Titanium.API.info('打印输出是调试的唯一方法');
编辑
这些api没有任何好的格式,所以你不能在Eclipse中通过帮助等方式获得普通的代码补全。Aptana,请帮帮我!
硬件
似乎编译器/工具不是多线程的,所以一个快速的计算机和一个快速的硬盘驱动器是必须的,因为你必须做大量的试验和错误。我提到过糟糕的文件吗?你必须把那里的一切都试一试,因为你不能相信它!
一些积极的事情
Open Source From previous projects I have promised myself never ever to use closed source again as you can't simply fix things just by throwing hours and manpower at it. Important when you are late in the project and need to deliver for a hard deadline. This is open source and I have been able to see why the tool chain breaks and actually fix it as well. Bugdatabase It's also open. You can simply see that your not alone and do a workaround instead of another 4 hours spent on trial&error. Community Seems to be active on their forums.
Bugs
Titanium 1.4 is not threadsafe. That means if you make use of threads (use the url: property in a createWindow call) and program like the threads are working and send events with data back and forth you run into a lot of very, very strange stuff - lost handlers, lost windows, too many events, too few events, etc. etc. This is all dependent on the timing, putting the rows of code in different order might crash or heal your application. Adding a window in another file.js breaks your app.js execution... This also trashes internal datastructures in Titanium, as they sometimes can update internal datastructures in paralell, overwriting a just changed value with something else.
我在使用Titanium时遇到的很多问题都来自于我使用实时系统的背景,比如支持数百个线程、事件和消息传递的OSE。这应该在Titanium 1.4中工作,但它并不可靠。
Javascript (which is new to me) dies silently on runtime errors. This also means that small and common bugs, like misspelling a variable name or reading in a null-pointer does not crash when it should so you can debug it. Instead parts of your program just stop working, for instance an eventhandler, because you misplaced/misstyped a character. Then we have more simple bugs in Titanium, like some parameters not working in the functions (which is quite common on the Android platform at least). Trial and Error debug cycle speed Having run Titnium Developer on several computers, I noticed that the bottleneck is the harddrive. An SSD drive on a laptop makes the build cycle about 3-5 times faster than on a 4200 rpm drive. On a desktop, having dual drives in RAID 1 (striping mode) makes the build about 25 percent faster than on a single drive with a somewhat faster CPU and it also beats the SSD drive laptop.
总结
从这个帖子里的评论来看,似乎有一场像这样的工具可以提供应用程序的平台数量之争。API的数量似乎是关键的卖点。
当你开始使用它的时候,它会非常闪亮。如果你查看打开的bug跟踪器,你会发现bug数量的增长速度一直快于已修复的bug数量。这通常是开发人员不断添加更多功能的标志,而不是专注于减少错误的数量。
作为一个为客户提供多平台应用的顾问,我不确定这是否比在两个平台上开发本地应用更快。这是因为当你达到速度时,你使用钛的速度很快,但突然你向下看,发现自己在一个如此深的洞里,你不知道必须花费多少小时来解决问题。你可以在特定的期限/时间/成本下不承诺特定的功能。
关于我自己:我已经用wxPython使用Python两年了。(GUI是不一致的,但从未像这样中断。可能是我不理解Javascript和Titanium使用的线程模型,但根据他们的开放论坛,我不是一个人,GUI对象突然使用错误的上下文/不更新..??)在此之前,我有移动设备的C和ASM编程背景。
[编辑-添加了错误的部分,不线程安全] [编辑-现在已经工作了一个多月,主要是在PC上,但也有一些在OS X上。增加了iPhone和Android的双重目标。增加了试错调试周期