码迷,mamicode.com
首页 > 其他好文 > 详细

Cordova自定义插件开发

时间:2016-05-10 12:30:57      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

   刚刚接触 phonegap 因为配环境遇到各种各样问题.,所以写一个篇文章希望能给大家节约点时间本文主讲windows系统下的phonegap的环境搭建 ,Android视角为主.iOS用户可参考;

  

1:首先介绍搭建环境的基本准备: 

java JDK   (http://www.oracle.com/technetwork/java/javase/downloads/index.html)

2 android SDK  http://developer.android.com/sdk/index.html  

3 Node         https://nodejs.org/en/

4 sublime       http://www.sublimetext.com/2:

2:接下来开始phonegap的安装了:

1:phonegap 官网 点击

在控制台运行命令:
    npm install -g phonegap                    ( Mac使用: sudo npm install -g phonegap )

//等待安装   完成后安装 cordova:

    npm install -g cordova                        ( Mac使用: sudo npm install -g cordova )

安装完成后  


检验语句:

phonegap -version

cordova -version

3:cordova自定义插件

  自定义插件目录结构

    这里的 src 对应不同的平台,www 放我们的 javascript 文件,plugin.xml 是插件的配置文件。

  技术分享

下面了解下java文件的一些代码

技术分享

          技术分享   

 下面说一下YouYunIMPlugin.js文件

       技术分享 

导出

技术分享

继续说一下非常重要的配置文件plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- id: 插件的标识-->
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="youyun-cn-plugin-im" version="1.0.0">
<!--name:插件的名称-->
<name>YouYunIMPlugin</name>
<!--description:描述信息-->
<description>YouYunIMPlugin Description</description>
<author>YouYun</author>
<license>Apache 2.0 License</license>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<!--js-module:对应我们的 javascript 文件 src:属性指向 www/YouYunIMPlugin.js-->
<js-module src="www/YouYunIMPlugin.js" name="YouYunIMPlugin">
<clobbers target="YouYunIMPlugin" />
</js-module>
<!--platform:支持的平台-->
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="YouYunIMPlugin">
<param name="ios-package" value="YouYunIMPlugin" />
<param name="onload" value="true" />
</feature>
</config-file>
<config-file target="*-Info.plist" parent="YYSDKConfig">
<dict>
<key>CLIENT_ID</key>
<string>1-20082-3e1632fba5606ffd129dd9d08b8df64a-ios</string>
</dict>
<dict>
<key>SECRET</key>
<string>c5bcda37516e2c8dbd41baa2df74821c</string>
</dict>
</config-file>
<header-file src="src/ios/include/WChatCommon.h" target-dir="include" />
<header-file src="src/ios/include/WChatSDK+ServiceRequest.h" target-dir="include" />
<header-file src="src/ios/include/WChatSDK.h" target-dir="include" />
<header-file src="src/ios/YouYunIMPlugin.h" />
<header-file src="src/ios/YouYunApplicationHandler.h" />
<source-file src="src/ios/libWChatSDK.a" framework="true"/>
<source-file src="src/ios/include/public.der" target-dir="include"/>
<source-file src="src/ios/YouYunIMPlugin.m" />
<source-file src="src/ios/YouYunApplicationHandler.m" />
<!-- frameworks -->
<framework src="libz.dylib" weak="true" />
<framework src="libsqlite3.dylib" />
<framework src="CFNetwork.framework" />
<framework src="CoreTelephony.framework" />
<framework src="SystemConfiguration.framework" />
<framework src="Foundation.framework" />
<framework src="UIKit.framework" />
</platform>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="YouYunIMPlugin">
<!--包名:io.youyun.cordova,类名:YouYunIMPlugin-->
<param name="android-package" value="io.youyun.cordova.YouYunIMPlugin" />
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<meta-data android:name="CLIENT_ID" android:value="1-20082-3e1632fba5606ffd129dd9d08b8df64a-android"/>
<meta-data android:name="SECRET" android:value="c5bcda37516e2c8dbd41baa2df74821c"/>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" android:resizeable="true" android:anyDensity="true" />
<!--设定的使用权限-->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</config-file>
<!--将src这个路径下的jar包拷贝到libs平台的libs文件夹下面去-->
<source-file src="src/android/commons-fileupload-1.2.1.jar" target-dir="libs"></source-file>
<source-file src="src/android/commons-httpclient-3.1.jar" target-dir="libs"></source-file>
<source-file src="src/android/commons-lang-2.6.jar" target-dir="libs"></source-file>
<source-file src="src/android/protobuf-java-2.4.1.jar" target-dir="libs"></source-file>
<source-file src="src/android/push-sdk-android-1.0.jar" target-dir="libs"></source-file>
<source-file src="src/android/weimi-sdk-android-1.0.0.jar" target-dir="libs"></source-file>

<source-file src="src/android/ChatApiCallback.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/ChatType.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouyunChatApi.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouyunChatApiImpl.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouYunIMPlugin.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouyunInstance.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouyunReceiveMsgThread.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
<source-file src="src/android/YouyunUtil.java" target-dir="src/cn/youyun/cordova/YouYunIMPlugin/"></source-file>
</platform>
</plugin>

如何使用插件

创建应用程序

  cordova create hello com.example.hello HelloWorld 

添加平台

  cordova platform add android

  cordova platform add ios

完成后运行以下命令查看:

  cordova platfrom list

移除Android平台支持

  cordova platform rm android

安装插件

  cordova plugin add [自定义的插件目录]

删除插件

  cordova plugin rm [插件名称]

 

运行以下命令编译应用程序:

  cordova build或 cordova build android  //只针对Andorid平台编译

技术分享

 

 




  

 

 

 

 

 

Cordova自定义插件开发

标签:

原文地址:http://www.cnblogs.com/yinxiaopeng/p/5461513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!