Configure PhoneGap to iOS

Source: Internet
Author: User



Download PhoneGap
You need to nodejs the environment before installing PHONEGAP, download Nodejs and install it. The purpose of the installation environment is to use the PhoneGap command line.

3. Install phonegap Use command
$PHONEGAP Create My-app
$CD My-app
$phonegap Run IOS
This automatically creates an iOS environment that you can find in the directory my-app/platforms/. The system automatically creates an iOS PhoneGap project for us. This item is in the default directory.
4. Customizing the Project Creation Path
Command: PhoneGap Create < project directory > < project id> < project name >
The Helloword directory is created automatically, and then the CD to the platforms directory executes the $PHONEGAP run iOS command. This allows you to customize the creation of the PHONEGAP project.
As can be seen from the directory, widget-related project files are placed in the staging file directory, in the WWW folder has specific programming files. There are also various mobile platform adaptation information and resource files.

iOS-related files
Classes:
Proxy and main interface classes
Plugins: Empty Directory
Other Sources:
PCH file and program entry file
Resources:
Resource files: Pictures, plist
Frameworks: Class Library

Why the program runs index.html:
The Cdvconfigparser class has an attribute startpage, which, in method LoadSettings, determines that the default page is executed if no settings are specified for the start page.


The project run relies on the class library provided in the PHONEGAP, but there are no related files found in the project, and the analysis finds that there is a copy www directory entry in build phases, where the shell writes/bin/sh execution of the shell in cordova/ The lib/copy-www-build-step.sh. The test found that SH is an executable file for UNIX execution scripts.
Cordova/lib/copy-www-build-step.sh in the/bin/sh-c directory.
In this SH file there is a code cordova/lib/copy-www-build-step.sh, which was created when PhoneGap was created, under Platforms/ios/cordova/lib in the project. iOS directory is the root of the program, so the configuration file cordova/lib/copy-www-build-step.sh can be found with this path, SH found this file will execute copy-www-build-step.sh inside the path configuration code.







Cordova is PhoneGap's name changed by Adobe's takeover.

First, JS and OC Communication principle:
1. JS uses two ways to communicate with Objective-c, one is to use XMLHttpRequest to initiate the request and the other is to set the SRC attribute of the transparent IFRAME.
1) The JS end uses XMLHttpRequest to initiate a request, while on the objective-c side uses a nsurlprotocol subclass to check each request, if the address is/!gap_exec, is considered to be a request for Cordova communication, directly intercept , interception can be done by analyzing the requested data and distributing it to different plug-in classes (subclasses of the Cdvplugin Class).

2) Create a transparent iframe on the JS side, set this ifame src as a custom protocol, while Ifame's src changes, UIWebView will first callback its delegate Webview:shouldstartloadwithre Quest:navigationtype: Method

Second, OC and JS communication principle
Through UIWebView Square stringbyevaluatingjavascriptfromstring: Executes a section of JS code, can achieve OC and JS communication effect.

Third, JS request objective-c,objective-c return results to JS
After the iOS native code gets callbackid, service, action, and Actionargs, the following processing is done:
1. Find the corresponding plug-in class according to the service parameters
2. Find the corresponding processing method in the plug-in class according to the action parameter, and pass the Actionargs as part of the processing method request parameter to the processing method
3. After the processing is completed, the processing results and Callbackid are returned to the JS end, and the JS side will find the callback method according to Callbackid, and pass the processing result to the callback method.

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.