博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ionic2 分享(微信分享+QQ分享+复制到剪贴板+微博分享)
阅读量:6951 次
发布时间:2019-06-27

本文共 4203 字,大约阅读时间需要 14 分钟。

ionic2 集成微信sdk

github地址:

使用示例:
cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID(你的微信开放平台id)
cordova build ios or cordova build android
分享朋友圈:(其中toastService是我自己封装的toast方法替换成自己对应的方法就可以了)

shareWxSession(){    let wechat = (
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 = (
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地址:

cordova plugin add --variable QQ_APP_ID=YOUR_QQ_APPID (QQ开放平台appid)
分享QQ:

shareQQ(){      let qq = (
window).QQSDK; let that = this; qq.checkClientInstalled(function () { var args:any = {}; args.scene = qq.Scene.QQ;//QQSDK.Scene.QQZone,QQSDK.Scene.Favorite args.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 error this.toastService.show('您没有安装QQ!'); }); }

分享QQ空间:

shareQZone(){  let qq = (
window).QQSDK; let that = this; qq.checkClientInstalled(function () { var args:any = {}; args.scene = qq.Scene.QQZone;//QQSDK.Scene.QQZone,QQSDK.Scene.Favorite args.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 error this.toastService.show('您没有安装QQ!'); }); }

复制到剪贴板

文档地址:

添加Clipboard的插件:ionic plugin add
使用方法:

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

微博分享

github地址:

cordova plugin add https://github.com/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 = (
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 http://www.sinaimg.cn/blog/developer/wiki/LOGO_64x64.png will be the defualt one args.defaultText = ""; wb.shareToWeibo(function () { this.toastService.show('分享成功','bottom',4000); }, function (failReason) { // console.log(failReason); }, args); } ,function(){ this.toastService.show('您没有安装Weibo!'); });}`

转载地址:http://rjjil.baihongyu.com/

你可能感兴趣的文章
Swift基础语法学习-3.类型转换
查看>>
向你安利了一个编辑器,并丢给你一堆插件
查看>>
Flutter 入门之 ListTile 使用指南
查看>>
Android Material Design控件使用(一)——ConstraintLayout 约束布局
查看>>
为什么区块链世界既需要计算机科学家也需要经济学家?
查看>>
Atom 微信小程序文件代码高亮
查看>>
Qtum量子链周报(3月18日-3月24日)
查看>>
couchbase介绍与实践(一)
查看>>
JavaScript正则表达式(2)
查看>>
开源 | Rainbond 3.5 pre-release
查看>>
css中px、em、rem区别与使用
查看>>
两个男同事打架 公司决定要不离职, 要不手牵手一下午, 结果他俩就选择.........
查看>>
(三)java版spring cloud+spring boot 社交电子商务平台 - Spring Cloud集成项目简介
查看>>
本地搭建ios测试包上传下载安装环境(类似蒲公英)
查看>>
BCH大区块导致中心化其实是伪命题
查看>>
Linux软件包管理之源码安装
查看>>
求两个数的最大公约数两种方法
查看>>
结对编程讲义-PPT
查看>>
SOLR
查看>>
配置Nutch模拟浏览器以绕过反爬虫限制
查看>>