ionic cordova plugin for ios
源代码结构目录:
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的更多相关文章
- ionic cordova plugin 安装和使用
注意事项 ionic1需要ng-cordova plugin的使用都需要放到deviceready事件的回调中, 设备准备好了才能设备交互 plugin只有在真机上才有效果, 模拟器(部分)和brow ...
- ionic cordova plugin simple demo
要用cordova plugin 的话还是需要设置一下的 1. 下载 ng-cordova.js download the zip file here 2. 在index.html 中引用 (cord ...
- [Cordova] Plugin里使用iOS Framework
[Cordova] Plugin里使用iOS Framework 前言 开发Cordova Plugin的时候,在Native Code里使用第三方Library,除了可以加速项目的时程.也避免了重复 ...
- Ionic Cordova 调用原生 Api 实现拍照上传 图片到服务器功能
Ionic 调用 Device 设备 Api 获取手机的设备信息 1. 找到对应的Api: https://ionicframework.com/docs/native/device/ 2. 安装相关 ...
- [Cordova] Plugin开发入门
[Cordova] Plugin开发入门 Overview Cordova的设计概念,是在APP上透过Web控件来呈现Web页面,让Web开发人员可以操作熟悉的语言.工具来开发APP.使用Web页面来 ...
- ionic cordova screenshot 使用和操作
如何调用cordova 中的screenshot插件进行截图 首先添加 ionic cordova plugin add com.darktalker.cordova.screenshot npm i ...
- 关于在浏览器中测试cordova plugin的注意事项。
本文介绍有关Ionic Native能力的注意事项: 1)按官方文档安装对应的cordova插件,比如:ionic cordova plugin add cordova-plugin-datepick ...
- 在meteor中如何使用ionic组件tabs,及如何添加使用cordova plugin inappbrower
更新框架: meteor update meteor框架的优点不言而喻,它大大减轻了App前后端开发的负担,今年5月又获得B轮2000万融资,代表了市场对它一个免费.开源开发框架的肯定.cordova ...
- Mac下安装ionic和cordova,并生成iOS项目
为了开发HTML5,除了最新使用React Native等之外,目前首选的为稳定的ionic+Angularjs来开发iOS和android. Ionic(ionicframework一款接近原生的H ...
随机推荐
- uva 10617
当s[i] = s[j] dp[i][j] = 1+dp[i+1][j-1]+dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1] = 1+dp[i][j-1]+dp[i+1][j ...
- pl/sql tutorial
http://plsql-tutorial.com/plsql-procedures.htm What is PL/SQL? PL/SQL stands for Procedural Language ...
- poj 1797 Heavy Transportation(最短路变种2,连通图的最小边)
题目 改动见下,请自行画图理解 具体细节也请看下面的代码: 这个花了300多ms #define _CRT_SECURE_NO_WARNINGS #include<string.h> #i ...
- 深入浅出ES6(五):不定参数和默认参数
作者 Jason Orendorff github主页 https://github.com/jorendorff 不定参数 我们通常使用可变参函数来构造API,可变参函数可接受任意数量的参数.例 ...
- java基础知识回顾之java Thread类学习(四)--java多线程安全问题(锁)
上一节售票系统中我们发现,打印出了错票,0,-1,出现了多线程安全问题.我们分析为什么会发生多线程安全问题? 看下面线程的主要代码: @Override public void run() { // ...
- 李洪强iOS开发之keychain的使用
通常情况下,我们用NSUserDefaults存储数据信息,但是对于一些私密信息,比如密码.证书等等,就需要使用更为安全的keychain了.keychain里保存的信息不会因App被删除而丢失,在用 ...
- lintcode 中等题:kth-largest-element 第k大元素
题目 第k大元素 在数组中找到第k大的元素 样例 给出数组[9,3,2,4,8],第三大的元素是4 给出数组 [1,2,3,4,5],第一大的元素是5,第二大的元素是4,第三大的元素是3,以此类推 注 ...
- 用React.addons.TestUtils、Jasmine进行单元测试
一.用到的工具 1.React.addons.TestUtils 2.Jasmine 3.Browserify(处理jsx文件的require依赖关系) 4.Reactify(能和browserify ...
- 261. Graph Valid Tree
题目: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nod ...
- 54. Spiral Matrix
题目: Given a matrix of m x n elements (m rows, ncolumns), return all elements of the matrix in spiral ...