如何通过ionic中的社交共享插件共享图像文件链接数组或多个图像?

时间:2019-02-26 20:51:49

标签: cordova ionic-framework cordova-plugins ionic4

我正在尝试通过ionicv4中的社交共享插件共享一系列动态创建的图像文件链接。现在,我正在使用WhatsApp对其进行测试。但这给了我一个TS错误,无法在字符串类型中传递arr []。我确实了解此错误,但需要解决此问题。我做了类似的事情

this.socialSharing.shareViaWhatsApp(null, imageArr , null);

2 个答案:

答案 0 :(得分:1)

我认为第二个参数应该是一个字符串,而您的imageArr变量是一个数组。尝试改为传递字符串

您能否尝试创建类似的功能

const ArrayLikeImages = ('yourImage1', 'yourImage2', 'yourImage3') => arguments;

然后是行

this.socialSharing.shareViaWhatsApp(null, ArrayLikeImages , null);

答案 1 :(得分:0)

在异步中使用forloop

const imageurls = [arrayofImageLinks];
let array = [];


for (var _i = 0; _i < imageurls.length; _i++) {
    const url = imageurls[_i];

this.http.get(url, {
            responseType: ResponseContentType.Blob
          })
          .toPromise()
          .then(async (res: any) => {
            const imgBlob = new Blob([res._body], {
              type: res.headers.get("Content-Type")
            });

            var reader = new FileReader();
            reader.readAsDataURL(imgBlob);
            reader.onloadend = async () => {
              const base64data = reader.result;
              array.push(base64data);
            };
          })
          .catch(err => {
            console.log(err)
          });

}

this.socialSharing.shareViaWhatsApp("Title", "", array).then(() => {
//do something when done
}).catch(err => {
// Error Occured
console.log(err); 
});