标签: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); });
标签:des style blog ar io color os 使用 sp
原文地址:http://www.cnblogs.com/ToFlying/p/4168887.html