100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Ionic2 分享(微信分享+QQ分享+复制到剪贴板+微博分享)

Ionic2 分享(微信分享+QQ分享+复制到剪贴板+微博分享)

时间:2021-08-04 20:04:20

相关推荐

Ionic2 分享(微信分享+QQ分享+复制到剪贴板+微博分享)

ionic2 集成微信sdk

github地址:/xu-li/cord...

使用示例:

cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID(你的微信开放平台id)

cordova build ios or cordova build android

分享朋友圈:(其中toastService是我自己封装的toast方法替换成自己对应的方法就可以了)

shareWxSession(){let wechat = (<any>window).Wechat;wechat.isInstalled(function (installed) {if(!installed){this.toastService.show('您没有安装微信!');return ;}}, function (reason) {this.toastService.show("Failed: " + reason);});wechat.share({message: {title: this.shareImg,description: this.shareDesc,thumb: this.shareImg,media: {type: wechat.Type.LINK,webpageUrl: this.shareUrl}},scene: wechat.Scene.SESSION // share to SESSION}, function () {this.toastService.show('分享成功');}, function (reason) {console.log("Failed: " + reason);});}

分享微信好友:

shareWxTimeLine(){let wechat = (<any>window).Wechat;wechat.isInstalled(function (installed) {if(!installed){this.toastService.show('您没有安装微信!');return ;}}, function (reason) {this.toastService.show("Failed: " + reason);});wechat.share({message: {title: this.shareImg,description: this.shareDesc,thumb: this.shareImg,media: {type: wechat.Type.LINK,webpageUrl: this.shareUrl}},scene: wechat.Scene.TIMELINE // share to Timeline}, function () {this.toastService.show('分享成功','bottom',4000);}, function (reason) {console.log("Failed: " + reason);});}

ionic2集成QQsdk

github地址:/iVanPan/Co...

cordova plugin add /iVanPan/Co... --variable QQ_APP_ID=YOUR_QQ_APPID (QQ开放平台appid)

分享QQ:

shareQQ(){let qq = (<any>window).QQSDK;let that = this;qq.checkClientInstalled(function () {var args:any = {};args.scene = qq.Scene.QQ;//QQSDK.Scene.QQZone,QQSDK.Scene.Favoriteargs.url = that.shareUrl;args.title = that.shareTitle;args.description = that.shareDesc;args.image = that.shareImg;qq.shareNews(function () {this.toastService.show('分享成功');}, function (failReason) {// alert(failReason);},args);}, function () {// if installed QQ Client version is not supported sso,also will get this errorthis.toastService.show('您没有安装QQ!');});}

分享QQ空间:

shareQZone(){let qq = (<any>window).QQSDK;let that = this;qq.checkClientInstalled(function () {var args:any = {};args.scene = qq.Scene.QQZone;//QQSDK.Scene.QQZone,QQSDK.Scene.Favoriteargs.url = that.shareUrl;args.title = that.shareTitle;args.description = that.shareDesc;args.image = that.shareImg;qq.shareNews(function () {this.toastService.show('分享成功','bottom',4000);}, function (failReason) {// alert(failReason);},args);}, function () {// if installed QQ Client version is not supported sso,also will get this errorthis.toastService.show('您没有安装QQ!');});}

复制到剪贴板

文档地址:/doc...

添加Clipboard的插件:ionic plugin add /VersoSolut...

使用方法:

clipboard() {Clipboard.copy(this.shareUrl);this.toastService.show('已复制到剪贴板');}

微博分享

github地址:/iVanPan/co...

cordova plugin add /iVanPan/cordova_weibo.git --variable WEIBO_APP_ID=YOUR_WEIBO_APPID or cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=YOUR_WEIBO_APPID

使用方法:

shareWb(){let wb = (<any>window).YCWeibo;let that = this;wb.checkClientInstalled(function(){var args:any = {};args.url = that.shareUrl;args.title = that.shareTitle;args.description = that.shareDesc;;args.imageUrl = that.shareImg;//if you don't have imageUrl,for android /blog/developer/wiki/LOGO_64x64.png will be the defualt oneargs.defaultText = "";wb.shareToWeibo(function () {this.toastService.show('分享成功','bottom',4000);}, function (failReason) {// console.log(failReason);}, args);},function(){this.toastService.show('您没有安装Weibo!');});}`

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。