使用 JavaScript 构建本机应用程序的最佳方式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19925486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to build native applications with JavaScript?
提问by Michael Kisilenko
I've been playing for a while with phonegap, did some tests on my Android...
我玩phonegap已经有一段时间了,在我的Android上做了一些测试......
It's pretty nice.
这很不错。
My questions are:
What is the best (your favorite) framework to develop native mobile applications with web client side (HTML / JavaScript / CSS)?
我的问题是:
使用 Web 客户端(HTML / JavaScript / CSS)开发原生移动应用程序的最佳(您最喜欢的)框架是什么?
How easy is to build and maintain those applications in multiplatforms (iOS / Android / BlackBerry) parallel? Does it has many exceptions between different platforms (iOS / Android / BlackBerry)?
在多平台(iOS / Android / BlackBerry)并行构建和维护这些应用程序有多容易?不同平台(iOS / Android / BlackBerry)之间有很多例外吗?
What are the requirements to develop my app for iOS? Should I need a special IDE with special SDK? Must I have a Mac?
为 iOS 开发应用程序有哪些要求?我是否需要一个带有特殊 SDK 的特殊 IDE?我必须有 Mac 吗?
回答by Jacob Turner
We're currently building a native iOS application using React Native. It would be a shame if it wasn't included here.
我们目前正在使用React Native构建原生 iOS 应用程序。如果不包括在这里,那就太可惜了。
Pros:
优点:
- React treats the DOM as an implementation detail. This made the transition over to native UI very natural. It also removes the need for HTML/CSS when writing a native app. All you need is native components, written in JavaScript.
- Native components! The fundamental native components have already been bridged over to JavaScript, and there is a community busy at work bringing everything else over. The thing is, if you know or are willing to learn some Objective C or Java, there is an easy processto add any native module (or third-party module) to React Native.
- Quick iteration. There have been over 2600 commits to the master branch since it was open-sourced in March.
- You get all of the benefits of normal React: a virtual view layer, diffing, declarative UI creation, fantastic developer experience, and a stellar community.
- You can build for multiple platforms from the same repository, reusing much of the same codebase (application logic, mostly).
- React 将 DOM 视为实现细节。这使得向原生 UI 的过渡非常自然。在编写本机应用程序时,它还消除了对 HTML/CSS 的需要。您所需要的只是用 JavaScript 编写的本机组件。
- 原生组件!基本的本机组件已经桥接到 JavaScript,并且有一个社区正忙于将其他所有组件都带过来。问题是,如果你知道或愿意学习一些 Objective C 或 Java,有一个简单的过程可以将任何本机模块(或第三方模块)添加到 React Native。
- 快速迭代。自 3 月份开源以来,已经有超过 2600 次提交到 master 分支。
- 您可以获得普通 React 的所有好处:虚拟视图层、差异化、声明式 UI 创建、出色的开发人员体验和一流的社区。
- 您可以从同一个存储库为多个平台构建,重用大部分相同的代码库(主要是应用程序逻辑)。
Cons:
缺点:
- It's still young. There are a few features that require jimmy-rigging, a third-party library, or custom Objective-C/Java to get working.
- Some great third-party libraries that are tied to the DOM or Browser API still don't work on React Native, including React Router.
- The biggest pains have had to do with XCode and Apple's developer program, but there's no way to get around that.
- 它还很年轻。有一些功能需要 jimmy-rigging、第三方库或自定义 Objective-C/Java 才能工作。
- 一些与 DOM 或浏览器 API 相关联的优秀第三方库仍然无法在 React Native 上运行,包括 React Router。
- 最大的痛苦与 XCode 和 Apple 的开发人员计划有关,但没有办法解决这个问题。
How easy is to build and maintain those applications in multi-platforms?
在多平台中构建和维护这些应用程序有多容易?
React Native for Android was open-sourced on September 14th, 2015. I haven't used it yet, but here's what I've been able to learn so far. Update 10/21/16:React Native for the Windows Universal Platform was announced earlier this year. That means you can now use React Native to build apps for Windows desktop, Windows phones, and even Xbox!
React Native for Android 于 2015 年 9 月 14 日开源。我还没有使用它,但这是我目前能够学到的东西。2016 年 10 月 21 日更新:今年早些时候宣布了适用于 Windows 通用平台的 React Native。这意味着您现在可以使用 React Native 为 Windows 桌面、Windows 手机甚至 Xbox 构建应用程序!
React Native is notintended to be a write once, run anywhere mentality. They adopt a learn once, write anywhere paradigm instead. iOS is a very different platform than Android, so sincere effort needs to be put into the design for either platform. The native APIs will also be different.
React Native并不打算成为一次编写,随处运行的心态。他们采用了一次学习,随处编写的范式。iOS 是一个与 Android 截然不同的平台,因此需要为任一平台的设计付出真诚的努力。原生 API 也会有所不同。
So, you will end up re-writing code for native components and APIs. However, much of your application logic can be re-used. In fact, React-Native is organized so that you can keep both your Android and iOS applications in the same repository, so that you can re-use the same code when possible. I think it's brilliant, but only time will tell. According to them, it works well so far.
因此,您最终会为本机组件和 API 重新编写代码。但是,您的大部分应用程序逻辑都可以重用。事实上,React-Native 是经过组织的,因此您可以将 Android 和 iOS 应用程序保存在同一个存储库中,以便您可以在可能的情况下重用相同的代码。我认为这很棒,但只有时间会证明一切。 据他们说,到目前为止,它运行良好。
By the way, a team at Facebook built an iOS app using React Native, then turned around and built the Android version in three months using 87% of the same code base.
顺便说一句,Facebook 的一个团队使用 React Native 构建了一个 iOS 应用程序,然后转身使用 87% 的相同代码库在三个月内构建了 Android 版本。
What are the requirements to develop my app for iOS?
为 iOS 开发应用程序有哪些要求?
Currently, you need a Mac and XCode in order to deploy. Currently there are very few ways around this. According to this issueand from conversations on Slack, once deployed, you can actually develop from a Windows or Linux machine. Facebook is also working on open-sourcing all of their Nuclidepackages, which, according to their presentation at F8, will include tools to package and build without XCode.
目前,您需要 Mac 和 XCode 才能部署。目前解决这个问题的方法很少。根据this issue和Slack上的对话,一旦部署,您实际上可以从Windows或Linux机器进行开发。Facebook 还致力于开源他们所有的Nuclide软件包,根据他们在 F8上的介绍,这些软件包将包括无需 XCode 即可打包和构建的工具。
Overall, React Native has been a stellar experience. It is, in my opinion, head and shoulders above anything else currently out there. The feeling within the community is also very positive. I can only assume it will get better with time.
总的来说,React Native 是一次出色的体验。在我看来,这是目前最重要的。社区内的感觉也非常积极。我只能假设随着时间的推移它会变得更好。
回答by chomasek
If your app is going to be very simple (for example a port of existing web app) and you need it only on one platform and it does not need integration with phone-specific features you may want to simply use a WebView on the selected platform. If your selected platform is iOS and you don't have any programming skills, you can follow these steps:
如果您的应用程序将非常简单(例如现有 Web 应用程序的端口)并且您只需要在一个平台上使用它并且不需要与手机特定功能集成,您可能只想在所选平台上使用 WebView . 如果您选择的平台是 iOS 并且您没有任何编程技能,您可以按照以下步骤操作:
- Download xCode on your Mac,
- Download this simple web view app project: https://github.com/nomtek/iOSWebViewApp
- Open the simple web view app within xCode
- Add your HTMLs to the project
- Run it :)
- 在 Mac 上下载 xCode,
- 下载这个简单的 web view app 项目:https: //github.com/nomtek/iOSWebViewApp
- 在 xCode 中打开简单的 Web 视图应用程序
- 将您的 HTML 添加到项目中
- 运行 :)
Advantages of this approach:
这种方法的优点:
- Simple setup
- No extra libraries to load - the application starts much faster
- 简单的设置
- 无需加载额外的库 - 应用程序启动速度更快
回答by Indu Devanath
This is one arena that keeps changing, and it only gets better. Googling at the moment of your interest would be the best bet. At the time of this writing, I am watching the following right now, in no particular order:
这是一个不断变化的领域,而且只会变得更好。在您感兴趣的那一刻使用谷歌搜索将是最好的选择。在撰写本文时,我正在观看以下内容,没有特别的顺序:
回答by Sridhar R
these are the options
这些是选项
Phonegap : http://phonegap.com/
电话口:http://phonegap.com/
PhoneGap is a free and open source framework that allows you to create mobile apps using standardized web APIs for the platforms you care about. .Download the Phonegap.
PhoneGap 是一个免费的开源框架,允许您使用标准化的 Web API 为您关心的平台创建移动应用程序。.下载Phonegap。
Coronalabs : http://coronalabs.com/
实验室:http://coronalabs.com/
Corona SDK builds rich mobile apps for iOS, Android, Kindle and Nook. Build high quality >mobile apps in a fraction of the time.
Corona SDK 为 iOS、Android、Kindle 和 Nook 构建丰富的移动应用程序。在很短的时间内构建高质量的>移动应用程序。
Appcelerator : http://www.appcelerator.com/
应用加速器:http: //www.appcelerator.com/
Appcelerator is the only mobile first platform that enables enterprise to create, deliver >and analyze their mobile applications.
Appcelerator 是唯一使企业能够创建、交付和分析其移动应用程序的移动优先平台。
回答by Duarte TB
Phone Gap does look like your best option, if you are trying to use javascript to build a mobile app
如果您尝试使用 javascript 构建移动应用程序,Phone Gap 看起来确实是您的最佳选择
Yes, you will need a mac, because you will need to install XCODE (https://developer.apple.com/xcode/) - apple′s own IDE.
是的,你需要一个 mac,因为你需要安装 XCODE(https://developer.apple.com/xcode/)——苹果自己的 IDE。
回答by Rob Vermeulen
If you invest a bit in learning a new script language, Coronalabswould be your new weapon of choice. With it you can build native (cross-platform) apps and you can use a webview to add your HTML/CSS/Javascript stuff if you need it.
如果您在学习一门新的脚本语言方面投入了一些精力,Coronalabs将是您选择的新武器。有了它,您可以构建本机(跨平台)应用程序,如果需要,您可以使用 webview 添加 HTML/CSS/Javascript 内容。
回答by Adil Shaikh
At the moment React Native is the best option for creating mobile apps in JavaScript.
目前,React Native 是用 JavaScript 创建移动应用程序的最佳选择。
Here are my top 3 reasons:
以下是我的三大理由:
Very active development and updates - After all it originated at FB
Negligible learning curve
- Great online resources
非常活跃的开发和更新 - 毕竟它起源于 FB
可忽略的学习曲线
- 很棒的在线资源
I was able to write a small but functional app without previous React Native experience and even deploy it to the Google Play Store all within 2 days.
我能够在没有 React Native 经验的情况下编写一个小型但功能强大的应用程序,甚至在 2 天内将其部署到 Google Play 商店。
Also one great benefit that i see with React Native is that you can "eject" your app at any point in time and continue to work on it in Android Studio or XCode. This could be a big relief in projects that start simple but could get complex over a period of time.
我在 React Native 中看到的另一个好处是,您可以随时“弹出”您的应用程序,并继续在 Android Studio 或 XCode 中处理它。对于开始简单但经过一段时间可能变得复杂的项目来说,这可能是一个很大的缓解。
Here is short tutorial I put together while building my first react native app for Android: http://geekycentral.com/creating-a-native-android-app-using-javascript-hello-react-native/
这是我在为 Android 构建我的第一个 React Native 应用程序时整理的简短教程:http: //geekycentral.com/creating-a-native-android-app-using-javascript-hello-react-native/