React Native - can we share an image and text into whatsapp?

前端 未结 3 779
情书的邮戳
情书的邮戳 2021-01-04 13:27

I\'ve spent an hours to find a way to send/share an image (and text if possible) into whatsapp app using react native,

I\'ve read this question (in android) and this

3条回答
  •  情歌与酒
    2021-01-04 13:41

    I was using react native 0.59 version but still i was not able to share image and text(including a link) on whatsapp because the default react native share gets either message or url so it is necessary to use react-native-share library https://github.com/react-native-community/react-native-share . I also used rn-fetch-blob library to convert image url to base64 image data.

    shareImage= () => {
    RNFetchBlob.fetch('GET', `https://example.com/example.png`)
      .then(resp => {
        console.log('response : ', resp);
        console.log(resp.data);
        let base64image = resp.data;
        share('data:image/png;base64,' + base64image);
      })
      .catch(err => errorHandler(err));
    
    share = base64image => {
      console.log('base64image : ', base64image);
      let shareOptions = {
        title: 'Title',
        url: base64image,
        message: 'https://somelink.com some message',
        subject: 'Subject'
      };
    
      Share.open(shareOptions)
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          err && console.log(err);
        });
    };
    

    };

提交回复
热议问题