如何通过Ionic应用程序在WhatsApp上分享图像



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

我可以共享文本,但它不会添加图像

我可能完全做错了,请提前让我知道正确的方法,谢谢

为了在单击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 声明为字符串即可。

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

最新更新