如何通过离子应用程序在whatsapp上分享图像

时间:2017-07-29 04:53:28

标签: android ionic-framework cordova-plugins ngcordova

在cordovaSocialShare插件上需要一些帮助 我想通过在我的离子应用程序中选择的Whatsapp分享图像,但我无法分享图像

<form name = myForm controller="ExampleController" ng-
submit="ShareAnywhere(myForm)">
<div class="myDivClass">
<input type="file" ng-model="share.shareImage">
<button ng-click="Submitted=true">Share</button>
</div>
<form>

以下是我的控制器

app.controller('ExampleController',function($scope, $cordovaSocialSharing, $filter){
$scope.shareAnywhere=function(myForm){


    var eDate = new Date();
    var message = "Hi! this is an wahtsapp msg";
    var image = this.share.shareImage;
    var link = 'http://myAwsomeWebsite.com';
    var subject = 'My Subject';
    $cordovaSocialSharing.share(message, subject, image, link);
}
});

我可以分享文字,但不会添加图片

我可能会完全错误,请事先了解正确的做法是什么

2 个答案:

答案 0 :(得分:1)

通过单击HTML文件上添加的按钮来捕获图像:

takePicture(){
    Camera.getPicture({
        destinationType: Camera.DestinationType.DATA_URL,
        targetWidth: 1000,
        targetHeight: 1000
    }).then((imageData) => {
      // imageData is a base64 encoded string
        this.base64Image = "data:image/jpeg;base64," + imageData;

    }, (err) => {
        console.log(err);
    });
  }
sharePicture(){

// Share via whatsapp

this.socialSharing.shareViaWhatsApp(this.message,this.base64Image,this.url).then(() => {
  // Success!
}).catch(() => {
  // Error!
});
}

只需将消息,图像和URL声明为字符串即可。

答案 1 :(得分:0)

参数图像应该是Image的路径(URL)。而不是图像数据。

相关问题