Hybrid app Development: Second, about making wheels and adding Cordova to Xcode iOS app development

Source: Internet
Author: User

Reprint Please specify source: http://www.cnblogs.com/xdxer/p/4111552.html

"Ctrl + Left click on the image to view the original"

In the previous article on hybrid APP development, I discussed how to use UIWebView under iOS. But the functionality provided by the use of a uiwebview does not meet our needs at all.

Thinking about making wheels:

UIWebView in Uikit has provided a lot of functionality, such as communication between JavaScript and OBJC. But given the question, how do you implement JavaScript calls to some local hardware devices, such as cameras, audio, and local storage, in the hybrid App? The first thing to think about is to stipulate some protocols, to receive messages from JavaScript in uiwebviewdelegate and to control the local database access by OBJC code, to control the camera and audio, and so on. However, how to display the local webcam video on WebView is still difficult to achieve. So the question is, how do you implement these protocols, and have a wide range of applicability to allow the vast majority of developers to use this set of frameworks? This is the question of whether or not to build wheels. Of course, it is very laborious to build a wheel, and may hide a lot of bugs, if you use some of the existing non-open-source framework, there will be a lot of unsafe issues, and some of the framework legacy bug~ below to introduce an open source framework, Cordova, Its predecessor is PhoneGap, was acquired by Apache after the change into a Cordova ~

About Cordova:

http://cordova.apache.org/

Apache Cordova is an Open-source mobile development framework. It allows the web technologies such as HTML5, CSS3, and JavaScript for Cross-platform development, Avoidin G each mobile platforms ' native development language. Applications execute within wrappers targeted to all platform, and rely on Standards-compliant APIs bindings to access EAC H device ' s sensors, data, and network status.

Cordova is an open-source mobile development framework. It allows you to use standard Web technologies such as HTML5,CSS3 and JavaScript for cross-platform development, bypassing the different development languages of each mobile platform.

Use Apache Cordova if is:

    • A mobile developer interested in mixing native application components with a WebView (Special browser window) tha T can access device-level APIs, or if you want to develop a plugin interface between native and WebView components.

Apache Cordova can be used if you are integrating a webview that accesses a hardware-level API into a native application, or if you want to develop an interface plug-in that implements interaction between navtive and WebView components.

In Cordova-enabled WebView, you can provide a complete user interface for your app. It can also be used as a component embedded in the local native application on some platforms.

At the same time, we can develop their own plugins!

There are 2 different ways to use Cordova:

1.cross-platform (CLI) WORKFLOW:CLI is a high-level tool that allows you to build only one project on multiple platforms.

2.platform-centered Workflow: With native as the center, embedded in the form of WebView.

To use Cordova under Mac OS:

1. First install a node. js http://nodejs.org/download/

2. Open Terminal input following command $ sudo npm install–g Cordova

3. You can then start building the Cordova project, as follows:

$ CD desktop/

$ Cordova Create Xiadongxiang XDX Xiadongxiang

The first parameter above is the project name, the second is the ID, and the third is the folder name

We can join the iOS project after the establishment is complete.

$CD xiadongxiang/

$cordova Platform Add iOS

This command, of course, can also be andriod, but this article only discusses iOS

4. Use the Cordova platform LS to display installed platform projects and platforms that can be installed

5. $ Cordova Build iOS build iOS project

6. Open the project with Xcode and run:

The steps above describe how to build a simple project using Cordova, and then we'll look at how to add Cordova to an existing native project.

How to integrate Cordova components into the native application in webview form:

You can refer to the steps in this URL, but there are some areas that are not right.

Http://cordova.apache.org/docs/en/4.0.0/guide_platforms_ios_webview.md.html

What I'm describing is the order in which I joined the project ~

1. First use the terminal, build a project on the desktop, and join the project on the iOS platform.

$cordova Create XDX XDX XDX

$CD xdx/

$cordova Platform Add iOS

2. In the above project in the Platform/ios directory, find config. Drag into the native project.

3. Locate the Cordovalib folder in the above project, copy the entire folder to the native project directory, and drag the Cordovalib.xcodeproj file into the Navigation view.

4. Set the location in its identity as relative to Group:

5. Add the following 4 libraries to the Build phases in target in the native project ~

AssetsLibrary.framework
CoreLocation.framework
CoreGraphics.framework
MobileCoreServices.framework

6. Add Cordovalib to target Dependencies in build phases in native target:

7. Link Binary with Libraries in build phases in native target joins LIBCORDOVA.A:

8. In the building Settings in target:

Other Link Flags: Join –OBJC and –all_load (Error in official documentation here, pro-Test)

Header Search Paths:

"$ (target_build_dir)/usr/local/lib/include"
"$ (objroot)/uninstalledproducts/include"
"$ (Built_products_dir)"

9. Add a new view in Stroryboard, create a new viewcontroller inherit from Cdvviewcontroller, then drag the WWW folder from the iOS directory in the previously created project to the project, Remember to select Create folder in the opt-in option to create folders instead of group.

10. Then don't move anything, command + R can see the effect,

In fact, the Cdvviewcontroller in the HTML file configuration address can be defined, but the default is the WWW folder, so we do not have to change to run.

We can insert the following code before loading, specifying the folder and the Start page HTML file:

self.wwwFolderName = @"myfolder";
self.startPage = @"mypage.html"
接下来研究的方向就是如何使用 & 自己开发并且添加Cordova插件 –> 访问数据库、文件操作、音频、视频操作等,以及其实现的原理。

Hybrid app Development: Second, about making wheels and adding Cordova to Xcode iOS app development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.