【问题标题】:how to share images on whatsapp through ionic app如何通过 ionic 应用在 whatsapp 上共享图像
【发布时间】:2018-01-05 05:27:15
【问题描述】:

在 cordovaSocialShare 插件方面需要一点帮助 我正在尝试通过在我的 ionic 应用程序中选择的 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);
}
});

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

我可能做错了,请让我知道正确的方法是什么,提前谢谢

【问题讨论】:

    标签: android ionic-framework cordova-plugins ngcordova


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    用于捕获单击 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 声明为字符串。

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      相关资源
      最近更新 更多