tidev / appcelerator.social-share

A collection of API's to Social Share
Other
7 stars 2 forks source link

How to share text, image and url #12

Open raywoocn opened 3 years ago

raywoocn commented 3 years ago

The example only shows how to share a text ,how can I share a rich content which includes title, image and a url?

draggmen commented 3 years ago

Hello, example image with url const itemProviderImage = socialshare.createActivityItemProvider({ contentType: socialshare.Content_Type_Image, placeHolder: 'placeholder' }); global.itemProvider = itemProviderImage; itemProviderImage.fetchItem = function () { return image; // this is view.toImage(); //blob };

const itemProvider = socialshare.createActivityItemProvider({
  contentType: socialshare.Content_Type_String,
  placeHolder: 'placeholder'
});
global.itemProvider = itemProvider;
itemProvider.fetchItem = function () {
  return 'your_url';
};
itemProvider.activityType = socialshare.Activity_Type_Message;
const customActivity = socialshare.createCustomActivity({
  category: socialshare.Activity_Category_Share,
  title: 'your_url',
});
global.customActivity = customActivity;
socialshare.shareWithItems({
  activityItems: [ itemProviderImage,itemProvider ],
  activities: [ customActivity ],
  completionWithItemsHandler: function (e) {
    if (e.errorCode !== null || e.errorDomain !== null || e.errorDescription !== null) {
      alert('Error Occured: ' + e.errorDescription);
      return;
    }
  }
});