源代码结构目录:

payplugin:

|_src

  |_android

    |_PayPlugin.java

  |_ios

    |_CDVPayPlugin.h

    |_CDVPayPlugin.m

|_www

  |_payplugin.js

plugin.xml

--======================================

payplugin/www/payplugin.js

var exec = require('cordova/exec');
/*
window.payplugin = function(str, callback) {
cordova.exec(callback, function(err) {
callback('Nothing to echo.');
}, "jsnative", "echo", [str]);
};
//var o = new window.echo();
module.exports = window.payplugin;*/

/*
var HelloWorld = function() {};

HelloWorld.prototype.say = function() {
alert("Hello World");
};

var helloWorld = new HelloWorld();
module.exports = helloWorld;
*/

/*window.payplugin = {};
window.payplugin.add = function(args,args2,addSuc,addFaild) {
cordova.exec(addSuc, addFaild, "payplugin", "add", [args,args2]);
}
module.exports = window.payplugin;*/

var PayPlugin = function() {};

PayPlugin.prototype.pay = function(args,args2,addSuc,addFaild) {
cordova.exec(addSuc, addFaild, "payplugin", "pay", [args,args2]);
}

var payPlugin = new PayPlugin();
module.exports = payPlugin;

payplugin\plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.youpin.payplugin"
version="1.0.0">
<name>payplugin</name>
<description>Pay Plugin</description>
<license>Apache 2.0</license>
<keywords>payplugin</keywords>

<js-module src="www/payplugin.js" name="payplugin">
<clobbers target="PayPlugin" />
</js-module>

<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="payplugin">
<!-- CDVPayPlugin是类名 -->
<param name="ios-package" value="CDVPayPlugin"/>
</feature>
</config-file>

<header-file src="src/ios/CDVPayPlugin.h" />
<source-file src="src/ios/CDVPayPlugin.m" />
</platform>

<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="payplugin" >
<param name="android-package" value="com.youpin.payplugin"/>
</feature>
</config-file>

<source-file src="src/android/PayPlugin.java" target-dir="src/com/youpin/payplugin" />
</platform>
</plugin>

--=======================================

payplugin\src\ios\CDVPayPlugin.h

#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDV.h>

@interface CDVPayPlugin : CDVPlugin

- (void) pay:(CDVInvokedUrlCommand*)command;

@end

--=======================================

payplugin\src\ios\CDVPayPlugin.m

#import "CDVPayPlugin.h"
#import <Cordova/CDV.h>

@implementation CDVPayPlugin

- (void) pay:(CDVInvokedUrlCommand*)command{
CDVPluginResult* pluginResult = nil;
NSString* javaScript = nil;

@try {

NSString* prod = [command.arguments objectAtIndex:0];
NSString* money = [command.arguments objectAtIndex:1];

if (prod != nil
&& [prod length] > 0
&& money != nil
&& [money length] > 0) {

/**
*相加字符串
*/
NSString *addResult = [NSString stringWithFormat:@"%@%@", prod, money];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:addResult];
javaScript = [pluginResult toSuccessCallbackString:command.callbackId];

} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
javaScript = [pluginResult toErrorCallbackString:command.callbackId];
}
} @catch (NSException* exception) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[exception reason]];
javaScript = [pluginResult toErrorCallbackString:command.callbackId];
}

[self writeJavascript:javaScript];
}

@end

--============================================

payplugin\src\android\PayPlugin.java

package com.youpin;

import org.apache.cordova.CordovaPlugin;
import android.content.Context;
import android.util.Log;

public class PayPlugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("pay")) {
String arg1 = args.getString(0);
String arg2 = args.getString(1);
String message = "result is:" + arg1 + arg2;
this.echo(message, callbackContext);
return true;
}
return false;
}
}

安装方法

ionic plugin add payplugin

ionic build ios

uninstall:

ionic plugin remove com.youpin.payplugin

调用方法:

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {

$scope.$on('$ionicView.enter', function(e) {

/*navigator.jsnative("echome", function(echoValue) {
alert(echoValue); // should alert true.
});*/

PayPlugin.pay("youbi6","6.00",$scope.addSuc,$scope.addFiald);
});

/** 
* js回调函数 
*/ 
$scope.addSuc = function(result) {
  alert(result);
  console.log('addSuc='+result);
}
$scope.addFiald = function() {
  console.log('addFiald');
}
})

ionic cordova plugin for ios的更多相关文章

  1. ionic cordova plugin 安装和使用

    注意事项 ionic1需要ng-cordova plugin的使用都需要放到deviceready事件的回调中, 设备准备好了才能设备交互 plugin只有在真机上才有效果, 模拟器(部分)和brow ...

  2. ionic cordova plugin simple demo

    要用cordova plugin 的话还是需要设置一下的 1. 下载 ng-cordova.js download the zip file here 2. 在index.html 中引用 (cord ...

  3. [Cordova] Plugin里使用iOS Framework

    [Cordova] Plugin里使用iOS Framework 前言 开发Cordova Plugin的时候,在Native Code里使用第三方Library,除了可以加速项目的时程.也避免了重复 ...

  4. Ionic Cordova 调用原生 Api 实现拍照上传 图片到服务器功能

    Ionic 调用 Device 设备 Api 获取手机的设备信息 1. 找到对应的Api: https://ionicframework.com/docs/native/device/ 2. 安装相关 ...

  5. [Cordova] Plugin开发入门

    [Cordova] Plugin开发入门 Overview Cordova的设计概念,是在APP上透过Web控件来呈现Web页面,让Web开发人员可以操作熟悉的语言.工具来开发APP.使用Web页面来 ...

  6. ionic cordova screenshot 使用和操作

    如何调用cordova 中的screenshot插件进行截图 首先添加 ionic cordova plugin add com.darktalker.cordova.screenshot npm i ...

  7. 关于在浏览器中测试cordova plugin的注意事项。

    本文介绍有关Ionic Native能力的注意事项: 1)按官方文档安装对应的cordova插件,比如:ionic cordova plugin add cordova-plugin-datepick ...

  8. 在meteor中如何使用ionic组件tabs,及如何添加使用cordova plugin inappbrower

    更新框架: meteor update meteor框架的优点不言而喻,它大大减轻了App前后端开发的负担,今年5月又获得B轮2000万融资,代表了市场对它一个免费.开源开发框架的肯定.cordova ...

  9. Mac下安装ionic和cordova,并生成iOS项目

    为了开发HTML5,除了最新使用React Native等之外,目前首选的为稳定的ionic+Angularjs来开发iOS和android. Ionic(ionicframework一款接近原生的H ...

随机推荐

  1. stdint.h 文件 int8_t uint8_t int16_t uint16_t

    http://blog.chinaunix.net/uid-26588712-id-3068151.html c++ 数据类型 按照posix标准,一般整型对应的*_t类型为:1字节     uint ...

  2. SVN--VisualSVN server 服务端和 TortoiseSVN客户端的基础使用

    前言 在上一文http://www.cnblogs.com/wql025/p/5177699.html中,我们讲到了使用SVN的第一步,即下载.安装SVN的服务端软件--VisualSVN serve ...

  3. Tern Server Timeout

  4. Spring中HibernateCallback的用法(转)

    Hibernate的复杂用法HibernateCallback HibernateTemplate还提供一种更加灵活的方式来操作数据库,通过这种方式可以完全使用Hibernate的操作方式.Hiber ...

  5. Linux下配置安装PHP环境

    参考别人的做法,遇到问题上网查,下面就是安装步骤. 一.安装Apache2.2.221.到官网下载  http://httpd.apache.org/download.cgi    2.解压    t ...

  6. Unity3d Detect NetState

    public static bool HasConnection() { System.Net.WebClient client; System.IO.Stream stream; try { usi ...

  7. Java 理论和实践: 了解泛型

    转载自 : http://www.ibm.com/developerworks/cn/java/j-jtp01255.html 表面上看起来,无论语法还是应用的环境(比如容器类),泛型类型(或者泛型) ...

  8. POJ1068Parencodings

    http://poj.org/problem?id=1068 这个题的话就是先把给出来的一串数字转化成括号,再把括号转化成要求的,最后输出就行了 #include<cstdio> #inc ...

  9. hdu 2177 取(2堆)石子游戏 博弈论

    由于要输出方案,变得复杂了.数据不是很大,首先打表,所有whthoff 的奇异局势. 然后直接判断是否为必胜局面. 如果必胜,首先判断能否直接同时相减得到.这里不需要遍历或者二分查找.由于两者同时减去 ...

  10. lintcode:合并排序数组 II

    题目: 合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A = [1, 2, 3, empty, empty] B = [4,5] 合并之后A将变成[1,2,3,4,5] ...