Codova支持小程序容器OpenApp+ 自動安裝 手動安裝

自動安裝

安裝cordova

> npm install -g cordova
> cordova create MyApp
> cd Cordova-Demo
> cordova platform add ios
> cordova plugin add @openapplus/cordova-openapplus-plugin

編寫codova插件調用函數

function onButtonClicked(){
    var CordovaOpenApplusPlugin = cordova.plugins.CordovaOpenApplusPlugin;
    CordovaOpenApplusPlugin.navigateToMiniProgram("openapplus://jsApp/Lr12JhPrE9bg7N4uoABBXY");
}
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
        var CordovaOpenApplusPlugin = cordova.plugins.CordovaOpenApplusPlugin;
        CordovaOpenApplusPlugin.start("oa606f78973e434c78933b869d8ba73c59","$2a$10$4bbR9ZNAhm74x3sckSLf/uPyR.E2JQvACCHP4xKtLt/OOpbJsiq9q");
        CordovaOpenApplusPlugin.enableLogging(true);

        document.querySelector('button').addEventListener('click', onButtonClicked);
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

完整Demo下載地址

https://github.com/linwaiwai/openapplus-demo/

手動安裝

下載插件

1、在Demo中找到插件下載CordovaOpenApplusPlugin
2、修改插件配置文件plugin.xml

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-openapplus-plugin" version="0.0.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>CordovaOpenApplusPlugin</name>
    <js-module name="CordovaOpenApplusPlugin" src="www/CordovaOpenApplusPlugin.js">
        <clobbers target="cordova.plugins.CordovaOpenApplusPlugin" />
    </js-module>
    <platform name="ios">
        <config-file parent="/*" target="config.xml">
            <feature name="CordovaOpenApplusPlugin">
                <param name="ios-package" value="CordovaOpenApplusPlugin" />
            </feature>
        </config-file>
        <source-file src="src/ios/CordovaOpenApplusPlugin.m" />
        <!-- <framework src="lib/OpenApplus.framework" embed="true" custom="true" /> -->
        <podspec>
          <config>
            <source url="https://github.com/CocoaPods/Specs.git"/>
          </config>
          <pods use-frameworks="true">
          <!--   <pod name="SDWebImage"  spec="3.7.5" />
            <pod name="SSZipArchive"  spec="1.6.2" />
            <pod name="SVProgressHUD"   spec="2.1.2" />
            <pod name="UMengUShare/Social/WeChat"   spec="6.3.0" />
            <pod name="MJRefresh"   spec="3.1.12" />
            <pod name="libextobjc"   spec="~> 0.4.1" />
            <pod name="AFNetworking"   spec="~> 3.2.1" /> -->
            <pod name="OpenApplus"   podspec="../../plugins/cordova-openapplus-plugin/podspec/OpenApplus.podspec" />
          </pods>
        </podspec>
    </platform>
</plugin>

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-openapplus-plugin" version="0.0.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>CordovaOpenApplusPlugin</name>
    <js-module name="CordovaOpenApplusPlugin" src="www/CordovaOpenApplusPlugin.js">
        <clobbers target="cordova.plugins.CordovaOpenApplusPlugin" />
    </js-module>
    <platform name="ios">
        <config-file parent="/*" target="config.xml">
            <feature name="CordovaOpenApplusPlugin">
                <param name="ios-package" value="CordovaOpenApplusPlugin" />
            </feature>
        </config-file>
        <source-file src="src/ios/CordovaOpenApplusPlugin.m" />
        <framework src="lib/OpenApplus.framework" embed="true" custom="true" />
        <podspec>
          <config>
            <source url="https://github.com/CocoaPods/Specs.git"/>
          </config>
          <pods use-frameworks="true">
                <pod name="SDWebImage"  spec="3.7.5" />
            <pod name="SSZipArchive"  spec="1.6.2" />
            <pod name="SVProgressHUD"   spec="2.1.2" />
            <pod name="UMengUShare/Social/WeChat"   spec="6.3.0" />
            <pod name="MJRefresh"   spec="3.1.12" />
            <pod name="libextobjc"   spec="~> 0.4.1" />
            <pod name="AFNetworking"   spec="~> 3.2.1" /> -->
          </pods>
        </podspec>
    </platform>
</plugin>

3、創建lib目錄,下載OpenApplus.framework 到 lib目錄下
3、cordova plugin add path/to/CordovaOpenApplusPlugin

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章