Phonegap for IOS Plugin插件开发
1.新建Phonegap工程MyPlugin
环境
xcode4.5.1
phonegap2.1.0
2.在Plugin文件夹下创建实现Plugin子类
[plain]
//
// MyPlugin.h
// MyPGPlugin
//
// Created by kllmctrl on 12-10-29.
//
//
#import <Cordova/CDV.h>
@interface MyPlugin : CDVPlugin
- (void) add:(CDVInvokedUrlCommand*)command;
@end
[plain]
#import "MyPlugin.h"
#import <Cordova/CDV.h>
@implementation MyPlugin
- (void) add:(CDVInvokedUrlCommand*)command{
CDVPluginResult* pluginResult = nil;
NSString* javaScript = nil;
@try {
NSString* echo = [command.arguments objectAtIndex:0];
NSString* echo2 = [command.arguments objectAtIndex:1];
if (echo != nil
&& [echo length] > 0
&& echo2 != nil
&& [echo2 length] > 0) {
/**
*相加字符串
*/
NSString *addResult = [NSString stringWithFormat:@"%@%@", echo, echo2];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:addResult];
javaScript = [pluginResult toSuccessCallbackString:command.callbackId];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
javaScript = [pluginResult toErrorCallbackString:command.callbackId];
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>