简体   繁体   中英

how to share images on whatsapp through ionic app

Need little help on cordovaSocialShare plugin I'm trying to share an image via Whatsapp which was selected in my ionic app but i'm not able to share the image

<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>

and below goes my controller

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);
}
});

I'm able to share the text but it wouldn't add image with it

I might be doing it completely wrong please let me know what is the correct way to do it thanks in advance

For capturing the image on click of button added at HTML file:

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!
});
}

Just declare the message, image and url as string.

the parameter image should be a path(URL) to the Image. and not the Image data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM