Cordova+ ios 外掛程式開發

來源:互聯網
上載者:User

標籤:des   style   blog   ar   io   color   os   使用   sp   

//ios 外掛程式開發//Echo iOS Plugin Example//配置  在config.xml中<platform name="ios">    <config-file target="config.xml" parent="/*">        <feature name="Echo">            <param name="ios-package" value="CDVEcho" />        </feature>    </config-file></platform>//Echo 標頭檔#import <Cordova/CDC.h>@interface CDVEcho:CDVPlugin//執行個體方法-(void) echo:(CDVInvokedUrlCommand *) command;@end//實現部分#import "CDVEcho.h"#import <Cordova/CDC.h>@implementation CDVEcho-(void) echo:(CDVInvokedUrlCommand *) command{    CDVPluginResult* pluginResult = nil;    NSString* echo = [command.arguments objectAtIndex:0];    if (echo != nil && [echo length] > 0)    {        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];    }     else     {        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];    }    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];}@end//線程處理 - (void)myPluginMethod:(CDVInvokedUrlCommand*)command{    // Check command.arguments here.    [self.commandDelegate runInBackground:^{        NSString* payload = nil;        // Some blocking logic...        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:payload];        // The sendPluginResult method is thread-safe.        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];    }];}//^{}:用來等待queue裡的最後一個block被執行掉,常用操作之一//^這個東西,說明一個塊函數,()這個東西是塊裡面需要的參數{}執行體//需要注意的是 weakSelf , 不是直接使用self, 防止循環參考 [self.commandDelegate runInBackground:^{}];JavaScript:1.successFunction:一個成功的回呼函數2.failFunction:一個錯誤回呼函數3.service: 一個本地類名4.action:本地類方法名5.args:數組的參數傳遞到本地環境  exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]);  Sample:    //定義cordova.define("com.JajaCy.cordova.echo", function(require, exports, module) {    var exec = require(‘cordova/exec‘);    var platform = require(‘cordova/platform‘);    /**     * Provides access to Echo on the device.     * 在裝置上提供通知。    */    module.exports = {        /**         * Demo         * @param {String} message         * @param {Function} completeCallback          */        echo: function(message,callback) {            exec(callback, function(err){                callback(‘Nothing to echo.‘);            }, "Echo", "echo", [message]);        }    };});//cordova_plugins.js  外掛程式配置cordova.define(‘cordova/plugin_list‘, function(require, exports, module) {    module.exports = [{            "file": "plugins/com.JajaCy.cordova.echo/www/echo.js",            "id": "com.JajaCy.cordova.echo.echo",            "merges": [                "window"//調用方法對象            ]        }];    module.exports.metadata =     // TOP OF METADATA    {        "com.JajaCy.cordova.echo": "0.0.1",    }    // BOTTOM OF METADATA});//調用 window.echo(‘Hello Echo!‘,function(data){    alert(data); });

 

Cordova+ ios 外掛程式開發

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.