ionic2微信分享

需要用到cordova-plugin-wechat这个cordova插件。

github地址:https://github.com/xu-li/cordova-plugin-wechat/tree/master

1.插件安装

命令行进入项目更目录,

命令行:

sudo ionic plugin add cordova-plugin-wechat --variable wechatappid=自己的微信appid

2.在项目src目录下找到declarations.d.ts文件,打开文件,

插入代码:

declare let Wechat;

这一步很重要,定义好后就可以在ts文件里直接调用插件了。

3.在ts文件里写一个测试方法

  test(){
    Wechat.share({
      text: "This is just a plain string",
      scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
      alert("Success");
    }, function (reason) {
      alert("Failed: " + reason);
    });
  }

4.在html调用,以下是我项目的代码,在头部导航来右侧增加一个分享按钮,点击调用分享测试代码


  
    
      商品详情
    
    
  

5.build

sudo ionic build ios

6.xcode中运行测试


详情见CrossInfo


你可能感兴趣的:(ionic)