Hybrid APP Development Summary

I recently made a Hybrid APP, and now I summarize the relevant knowledge and technology as follows

1. Technology used< /span>
html5, angularJs, cordova, ionic

Second, environment setup
To use cordova and ionic development, build a good cordova and ionic development environment
The steps are as follows:
1. Install node.js
Download link https://nodejs.org/en/
2. Install cordova
Enter npm install under cmd under windows cordova
Enter sudo npm install -g cordova

< div> 3. Install ioinc

Under windows, enter npm install under cmd. g ionic
Under mac, enter sudo npm install -g ionic
Sometimes it will be very slow to install with npm, you can use Taobao mirror
npm--registry https://registry.npm.taobao.org info underscore
Link to related questionshttps://cnodejs.org /topic/4f9904f9407edba21468f31e


3. Project creation, installation and operation
After the environment is set up, we create Project
1. Create Item
Use the command ioinc start yyt
After the command is completed, a yyt folder will be generated under the current path
2. Configure the platform
cd yyt to enter the project folder
Use the command ionic platform add android
If you want To configure ios is ionic platform add ios

3.build span>
Use the command ionic build android
If If it is ios, it is ionic build ios

4. Run to mobile phone
Android mobile phone
After connecting the phone, use ionic run android

div>

iPhone
After build, enter platfroms-- >ios
Find xxx.xcodeproj under this path and open it with Xcode
Use Xcode to run, you can run on your phone

Four. Development tools

< div> Here I use WebStorm to edit the code

Download WebStorm8.0 crack version Address
http://bbs.phonegap100.com/thread-1567-1-1.html

V. Code structure< /strong>
The code is written using the angularJs framework
The page display is based on index.html as the main page, which is different in ion-nav-view The content of the page, the html of each page is placed under www/templates
Each html page has a corresponding controller.js, these js The file is placed under www/js/controller

The app.js file defines related modules and configures the state machine

config.js is configured with related global variables

The http request uses the $http service of angularJs, and the relevant code is under service.js
style.css is a custom style file, generally used to rewrite related ionic styles to achieve custom style effects
VI. Development-related issues
1. Icon and start page < /div>

ionic can use commands to automatically generate icons and startup pages, as follows
(1) Under the resouces file under the project, put the picture icon.png and picture splash.png,
icon .png image requirements are 192*19 2px, splash.png requirements are 2208*2208px,
(2) Then switch to the project directory under cmd and enter the command
< /div>

ionic resources

After the completion, images of different sizes on the android platform and ios platform will be automatically generated, and the config.xml file will be automatically configured. < /div>

Related reference links div>

http://ionichina.com/topic/54e455ab2be672f1111c01e2

The problem I encountered: After the image is generated, an error will be reported after executing ionic build android:
Execution failed for task':mergeDebugResources'
libpng error: Read Error
< span style="font-size:16px">
Reason: There is a problem with some of the automatically generated pictures; solution : Find the problematic picture, replace it with a normal picture, and build it again
2. Plug-in
When you need to call native functions, you need Use plug-ins, here you can use third-party plug-ins, or write your own plug-ins
(1) You can use ngCordova's plug-ins when using third-party plug-ins. To use ngCordova, please refer to the following steps
①Install Git
② Download ngCordova download link http://angular-js.in/ng-cordova/< /span>
③Introduce the ng-cordova.js file
Bring ng-cordova.js or ng-cordova.min.js into index.html and put it before cordova.js and after the AngularJS Ionic file (because ngCordova relies on AngularJS).
Introducing the dependency of ng-cordova
In The dependency of ng-cordova is introduced in app.js, angular.module('myApp',['ngCordova']);
⑤ Installation plug-in documentation link http://ngcordova.com/docs/plugins/
The method of installing the plug-in is very simple, switch to the project under cmd Under the path, use the command cordova plugin add plugin url

command to delete plugin cordova plugin rm plugin id
Require View the plug-in list of the current project cordova plu gin list

The problem I encountered:
Reason: the cordova-android version is too low, just upgrade; use the command < /div>

cordova platform update [email protected]

(2) Write your own plug-in< /span>
After cordova3.X, you need to write the plug-in outside the project and insert it into the project by command
The steps to write the plug-in are as follows:
( 1) Create a folder under a certain path, such as EchoPlugin
(2) Create src, www folder, plugin in the EchoPlugin directory .xml file
src is for native code files, www is for js files, plugin.xml is for related configuration information
(3) Write java files, js files, plugin.xml files
< span style="font-size:16px"> (4) Use the command cordova plugin add under the project path to install the plugin into the project
Related reference links
http://www.wenzhixin.net.cn/2014/03/20/cordova_my_plugin< /span>


span>
3. Map
< span style="font-size:16px"> I am using the Baidu Map JavaScript API
For details, please refer to the official document< /span>
http://developer.baidu.com/map/index.php?title=jspopular

< div>

However, the function of mobile phone positioning cannot be realized with the Baidu Map JavaScript API. Try to use
html5 positioning function, I found that html5 can’t be implemented on Android phones. Later I used one < /div>

The map plug-in implements the positioning function, and the plug-in link is as follows:
http://www.phonegap100.com/plugininfo_40.html
Note: The data returned by the plug-in is a string. Not a js object, you need to split the string yourself to extract the longitude and latitude

The problem I encountered: Baidu map is not displayed in ion-content ,need To display the scroll parameter in ion-content to false


4.app update < /div>

App update needs to install and obtain local version plug-in, file plug-in, file-trasnser plug-in and file-opener plug-in
Related linksConnecthttp://bbs.phonegap100.com/thread-2046- 1-1.html
Implementation ideas, first obtain the version number of the program on the server when the program starts, and compare it with the local version number , If they are inconsistent, download the apk to the local, and then open

< span style="font-size:16px">
5. Push
I’m here to integrate a push SDK. You need to register an account in this push, register the application, and then integrate according to the official documentation.
After success, a clientid will be obtained. Related linkhttp://docs.getui.com/pages/viewpage.action?pageId=589866
The type of push message is determined by the server, such as opening a webpage, or opening an application, or transparently transmitting a message. For details, please refer to the official document div>

Realize the idea of ​​opening the specified page: server push Transparently transmit the message and push it in a JSON format string, and then the app side parses the JSON data to obtain the relevant parameters of
, and then the app Customize a Notification, click Notification to jump to the specified page


7. Other related links

Cordova official website http://cordova.apache.org/
Ionic official website http://ionicframework.com/

I recently made a Hybrid APP. Now I will add relevant knowledge The technical summary is as follows


1. Technology used

html5, angularJs, cordova, ionic


Second, environment setup

Require To use cordova and ionic development to build a good cordova and ionic development environment

The steps are as follows:

1. Install node.js

Download link https://nodejs. org/en/

2. Install cordova

Under windows, enter npm install under cmd and -g cordova

< span style="font-size:16px"> Under mac, enter sudo npm install -g cordova

< /p>

3. Install ioinc

wind Enter npm install under cmd under ows ionic

Enter sudo npm install -g ionic in the terminal under mac< /p>

Sometimes it will be slow to install with npm , You can use Taobao mirror

npm--registry https://registry.npm.taobao.org info underscore< /code>
Link to related questionshttps://cnodejs. org/topic/4f9904f9407edba21468f31e

npm--registry https://registry.npm.taobao.orginfo underscore< /span>

Related question linkhttps://cnodejs.org/topic/ 4f9904f9407edba21468f31e


3. Project creation, installation and operation

After the environment is set up, we will create the project p>

1. Create a project p>

Use the command ioinc start yyt

After the command is completed, A yyt folder will be generated under the current path

2. Configure the platform

cd yyt to enter the project folder

Use the command ionic platform add android

If you want to configure ios, it’s ionic platform add ios


3.build

Use the command ionic build android

ionic build ios if it’s ios

span>


4. Run To mobile phone

Android mobile phone

After connecting your phone, use ionic run android


iPhone

After build, enter platfroms-->ios

Find xxx.xcodeproj in this path and open it with Xcode

Use Xcode point to run, you can run on your phone


4. Development tools p>

Here I use WebStorm to edit the code

http://bbs.phonegap100.com/thread-1567-1-1.html


5. Code structure

The code is written using the angularJs framework

The page display is based on index.html as the main page. The content of different pages is displayed in ion-nav-view, and the html of each page is placed under www/templates

Each html page has a corresponding controller.js, these js files are placed under www/js/controller< /p>


Defined in the app.js file Related modules and configuration state machine

config.js configures related global variables

The http request uses the $http service of angularJs, and the relevant code is under service.js

style.css is a custom style file, generally used to rewrite related ionic styles, Achieve custom style effects

VI. Development-related issues

1. Icon and startup page

ionic can use commands to automatically generate icons and startup pages, the method is as follows

(1) Under the resouces file under the project, put the picture icon.png and picture splash.png,< /p>

icon.png image requirements are 192*192px, splash.png requirements are 2208*2208px,

(2) Then switch to the project directory under cmd and enter the command

span>

ionic resources


After finishing, it will automatically Generate an Images of different sizes on the droid platform and ios platform will be automatically configured under the config.xml file

>

Related reference links

http://ionichina.com/ topic/54e455ab2be672f1111c01e2


The problem I encountered: After the image is generated, an error will be reported after executing ionic build android:

p>

Execution failed for task':mergeDebugResources'

libpng error : Read Error


Reason: There is a problem with some of the automatically generated pictures; Solution: Find the problematic picture, replace it with a normal picture, and build it again

2. Plug-in

When you need to call native functions, you need to use plug-ins, here you can use third-party plug-ins, or write your own plug-ins

(1) You can use ngCordova’s plug-ins when using third-party plug-ins. To use ngCordova, please refer to the following steps< /span>

①Install Git

Download ngCordova download link http://angular-js.in/ng-cordova/

③ Import the ng-cordova.js file

span>

Bring ng-cordova.js or ng-cordova.min.js into index.html and put it before cordova.js, AngularJS Ionic After the document (because ngCordova relies on AngularJS).

④ Introduce the dependency of ng-cordova

Introduce the dependency of ng-cordova in app.js, angular.module('myApp',['ngCordova']);

⑤Install plug-in documentation link http://ngcordova.com/docs/plugins/

The method of installing the plug-in is very simple. Switch to the project path under cmd and use the command cordova plugin add plugin url

command to delete plugin cordova plugin rm plugin id

To view the plug-in list of the current project cordova plugin list


The problem I have encountered:

< span style="font-size:16px">

< span style="font-size:16px"> Reason: The cordova-android version is too low, you can upgrade; use the command

code style="margin:0px; padding:0px; border:0px; background-color:rgb(238,238,238)">cordova platform update [email protected]


(2) Write your own plug-in

After cordova3.X, you need to write the plug-in outside the project and insert it into the project by command

Steps to write the plug-in As follows:

(1) Create a folder under a certain path, such as EchoPlugin

(2) Create src, www folder, plugin.xml file in EchoPlugin directory

src is for native code files, www is for js files, and plugin.xml is related configuration information

( 3) Write the java file, js file, plugin.xml file

(4) Use the command cordova plugin add under the project path Path to install the plug-in into the project

Related reference links

http://www.wenzhixin.net.cn/2014/03/20/cordova_my_pl ugin


3. Map

I Here is the Baidu Map JavaScript API

For details, please refer to the official document

http://developer.baidu.com/map/index.php?title=jspopular

html5 positioning function, I found that html5 can’t be implemented on Android phones. Later I used one

          地图的插件实现了定位功能,插件链接如下:

           http://www.phonegap100.com /plugininfo_40.html

          注意:该插件返回的数据是字符串,不是js对象,需要自己拆分字符串,将经度、纬度提取出来


          我遇到的问题: 百度地图在ion-content中不显示,需要将ion-content中的scroll参数设置为false即可显示了



        4.app更新

          app更新需要装获取本地版本插件、file插件、file-trasnser插件和file-opener插件

          相关链http://bbs.phonegap100.com/thread-2046-1-1.html

          实现思路,在程序启动时先获取服务器上的程序的版本号,与本地版本号比较,如果不一致,则下载apk到本地,然后打开



        5.推送

          我这里是集成个推的SDK,需要在个推注册账号,登记应用,然后按照官方文档集成,集成

          成功后,会获取到一个clientid。相关链接http://docs.getui.com/pages/viewpage.action?pageId=589866

          推送消息的类型由服务端决定,比如是打开网页,或者打开应用、或者是透传消息,详情请见官方文档

                

          实现打开指定页面的思路:服务端推送透传消息,以JSON格式的字符串推送过来,然后app端解析JSON数据,获取相关

          的参数,然后app端自定义一个Notification,点击Notification跳转到指定的页面



七、其它相关链接

       cordova官网http://cordova.apache.org/

         ionic官网http://ionicframework.com/

Leave a Comment

Your email address will not be published.