| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4440 人关注过本帖
标题:IOS版添加phonegap--插件写法教程
只看楼主 加入收藏
angel1994
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-12-24
收藏
 问题点数:0 回复次数:0 
IOS版添加phonegap--插件写法教程
创建插件文件。
<1>创建baidumap.h
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>//这是最新插件需要引入的库文件
@interface baidumap : CDVPlugin
–(void)map:(CDVInvokedUrlCommand*)command;//这是最新插件的写法
@end


<2>创建baidumap.m
 #import “baidumap.h”
#import <Cordova/CDVPlugin.h>
@implementation baidumap
–(void)map:(CDVInvokedUrlCommand *)command{
CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0]; //获取冲js文件传过来的值
NSLog(@”Client Information: %@”,  echo);
if (echo != nil && [echo length] > 0) {
pluginResult=[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];//成功回调
}else{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];//失败回调
}
[ sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end


<3>在congfig.xml 文件中注册插件
<plugin name=”baidumap” value=”baidumap” />


<4>写js插件部分
 var cordovaRef = window.PhoneGap || window.Cordova || window.cordova;
function success () {
//Generic callback provided if the Cordova call to the native  Objective-C should be successful
//Note: Probably don’t want to do anything here… but provided nevertheless
}
function fail () {
//Generic callback provided if the Cordova call to the native Objective-C should fail
}
var baidumap = {
map: function(success, fail, str) {
cordova.exec(success, fail, “baidumap”, “map”, [str]);
}
};


<5>引入插件道你的index文件。
并执行以下方法:
function map(str){
baidumap.map(
function(echoValue){ alert(echoValue == “home”);
alert(echoValue);
},
function(err) { alert(err);},str);
}
<button type=”button” onClick=”map(‘home’)”>插件测试</button>


KeyMob是国内优秀的移动广告平台;为广告主、网站主和应用开发者提供专业服务。KeyMob通过稳定的广告SDK,进行精准的移动营销,为应用开发者快速提升广告的收入;
搜索更多相关主题的帖子: interface command import 
2015-12-24 14:41
快速回复:IOS版添加phonegap--插件写法教程
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014383 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved