Basic Issues and common summaries based on cordova development, cordova development issues

Source: Internet
Author: User

Basic Issues and common summaries based on cordova development, cordova development issues
Note: This specification is only applicable to the development specifications for Power Information. Other users can refer to this specification. Basic specifications

Compliant with web standards, semantic html, structure, performance, behavior separation, and excellent compatibility. In terms of page performance, code requirements are concise, clear, and orderly, minimizing server load as much as possible to ensure the fastest resolution speed.

2. Document specifications

Html, css, js, and image files are all placed in the agreed directory. The basic directory structure is shown in figure 2.1, and the Directory and file name cannot contain Chinese characters. Stylewith CSS files, pluginswith the cordovaplug on the platform, index.html is the application's first page, and icon.png is the application's icon. (Cordova. js and cordova_plugins.js are js files that interact with the platform. They must be placed in the root directory.)

Fig 2.1

3. Writing specifications3.1. Html Specification

1. Document Type Declaration and encoding: the uniform declaration is html5. The meta attribute makes the webpage width equal to the screen width by default, and the original scaling ratio is 1.0, that is, 100%. The encoding is unified to UTF-8, and IDE is used for hierarchical indentation During writing.

2. Try to place the css and js file URLs between

3. Add meta to the title on the mobile terminal and set the width = device-width, initial-scale = 1, user-scalable = no, and other ratio window codes.

Example:

<! DOCTYPE html> 

  

3.2. Reference css and js

Because the country network uses crodova, in order to make each mobile phone system use the same set of code, you must first reference cordova when creating a mobile APPWeb project. js, and then reference your other js and css.

(Friendly Description: cordova_plugins.js does not need to be referenced. It needs to be placed in the following directory and then called cordova. js. It will automatically read the configuration, so you don't have to worry about cordova_plugins.js .)

3.3. Common plug-ins3.3.1. Login plug-in

 

Mam. navigator. loadconfig. getUserInfo (1, function login (v) {// If getUserInfo is an apple, you do not need parameter 1. In the new version, you can directly use a callback function without parameters. Mam. navigator. loadconfig. getUserInfo (callback )});

  

3.3.2. Get Data plugin
The obtained data can be divided into get, post, getJSON, and postJSON extensions. We recommend that you use postJSONmam. navigator. ajax. postJSON (appcode, params, appservercode, successCallbac);/** parameter description: appcode: Application Deployment environment address (for example, "DLSH": http://pubtest.js.sgcc.com.cn) params: the data to be sent to the server, expressed in Key/value pairs. If you do not need to pass the parameter, pass. Appservercode: The specific interface resource (for example, "API" corresponds to:/dlsh_web/ajax/api. do) successCallback: Successful callback **/

 

3.3.3. Return and exit application plug-in

In general, each application returns to the previous page or to the specified page, or you can exit the current application directly. This js is used by every application, the following code example can be applied to all mobile h5 pages.

Sample Code:

Var devicePlatform; // obtain the current device function onDeviceReady () {devicePlatform = device. platform; if ("iOS" = devicePlatform) {mam. navigator. appmenu. setBackButton (null, null, "1"); // set the return button of the Apple mobile phone.} document. addEventListener ('backclick', hback);} function hback () {if ("iOS" = devicePlatform) {mam. navigator. appmenu. setBackButton (null, null, "0");} document. removeEventListener ('backbucket', hback); // Method 1: Exit mam directly. navigator. appmenu. exitApp (); // type 2: Jump directly to the corresponding page window. location. href = ".. /index.html "; // The third type: Jump directly to the previous page of History. back (-1 );}

 

Note: There are other plug-ins not explained, please referMobile interaction platform JavaScript interface design document

4. IOS and Android FAQ Summary

Error Message

Error example

Solution

Andriod can access the page
Apple cannot access

Index.html

Android and Apple both write index.html

Apple is case sensitive. Therefore, it must be
All lowercase letters, or all uppercase letters.
According to the defined format.

Unable to access the plug-in (no plug-in party is obtained
Method)

Neither apple nor android can.

1: Check whether cordova. js and public. js are referenced.
2: Check whether the plug-in exists in the plugins folder.
3: Check whether the referenced path is incorrect.

Android can display a line chart, not Apple

The test time is dead. Write as follows:
Var t_time = new Date ("2015-10-1 ");
Which can be accessed by Android. Apple reports invalid time

If there are five time formats during the test, they can be avoided only by strictly following the time format.

Apple does not display data
1) new Date ("month dd, yyyy hh: mm: ss ");
2) new Date ("month dd, yyyy ");
3) new Date (yyyy, mth, dd, hh, mm, ss );
4) new Date (yyyy, mth, dd );
5) new Date (MS );
Month: represents the name of a month in English, from January to December.

Mth: an integer representing the month, from (January 1, January) to 11 (January 1, December)

Dd: the day of a month, from 1 to 31.

Yyyy: The Year in four-digit format.

Hh: hours, from 0 (midnight) to 23)

Mm: The number of minutes, an integer from 0 to 59.

Ss: number of seconds, an integer from 0 to 59

Ms: Number of milliseconds, an integer greater than or equal to 0
New Date ("January 12,2006 22:19:35 ");

New Date ("January 12,2006 ");

New Date );

New Date (2007,0, 12 );

New Date (1137075575000 );

Or use the formatDate () method in public. js.

The Json string passed in the background. The foreground uses Json. Parse.
Now, Android is good, and Apple cannot display data.
(Note: If the json string transmitted in the background is not recognized by the foreground)

Json. Parse (v), which can be accessed by Android, but not by Apple

This platform does not support Json. parse, solution: eval ("(" + v + ")"). The latest version is supported. If you use the old version cordova, please use eval (although eval is a waste of memory, you can only use this)

Plug-ins not loaded in the pop-up of Apple mobile phone

Put cordova. js and cordova_plugins.js in
Android can load the specified js folder,
Apple pop-up box (information not loaded)

Put cordova. js and cordova_plugins.js in the root directory.
(Note: These two Js files must be stored in the root directory)

Apple does not load the drop-down box information

$ ("Drop-down box"). attr ("selected", true );
Supported by Android phones, not supported by Apple

Written as $ ("drop-down box"). prop ("selected", true );

 

4.1. Application Publishing

The corresponding table should be entered when the application is renewed. For details, see tutorial _ template.xlsx. If you need to bind an application account, you must enter the correct account authentication address. For details, refer to the platform group.Yao FeiRequest template.

 

Related Article

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.