Using PHONEGAP development based on HTML5 application two: The first PhoneGap application: Baidu

Source: Internet
Author: User

Previous blog post using PHONEGAP development based on HTML5 application one: phonegap introduction I introduced how to download the source code from the PHONEGAP official website and launch the first application, today we put the application of phonegap a little change, Let him achieve several features that compare the Bull fork:

1. Start a Web page

2. Start the camera

3. Start positioning

The old ritual, before we do these things, let's talk about the original reason:

First of all, we look back at the last said, in fact, PHONEGAP application has a special webview, it is Cdvviewcontroller, about this class we described in detail, now we first understand what this class did, it is actually called the iOS device controller class , then how does he know that the user is going to call a device like the camera, that is, by parsing the HTML JS code.

phonegap himself defined some JS code, let these JS code with Cdvviewcontroller This class to interact, The role of Cdvviewcontroller is to judge the server-side HTML code, if it is normal HTML directly display, if encountered phonegap custom JS code "translated" into the code called iOS. OK, the concept is complete, if you do not understand, we start to look at the example below.


is the official demo application directory, we only need to run after the package can be found (, the extension of the app means that it is a Mac system application, but the actual situation, it is an iOS app, that is, the extension is an IPA, so you can change the format through itunes, this is not much to say, You know what that means.) After opening, see the following list:


can see the WWW folder in the application, under the two files, a JS file, an HTML

And look at the Appdelegate code in Xcode:

Self.viewController.wwwFolderName = @ "www";    Self.viewController.startPage = @ "index.html";

The meaning of these two sentences is to refer to the directory name and file name

If you change into

    Self.viewController.startPage = @ "http://www.baidu.com";

Can be implemented to load the function of Baidu homepage, the effect is as follows:



It is obvious that Baidu first shows that there is no problem.

Next article, will give you to parse cordova.js this file, because this JS indicates all the operation of the iOS device JS code, and it interacts with Cdvviewcontroller, so the exception is important.


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.