react-native-share icon indicating copy to clipboard operation
react-native-share copied to clipboard

Share.shareSingle `Instagram` only opens AppStore, does not post to Instagram

Open lucksp opened this issue 1 year ago • 8 comments

Steps to reproduce

  1. Handle press action:
 const shareItem = async () => {
    const screenshot = await screenshotRef.current?.capture?.();

    await Share.shareSingle({
      backgroundImage: require('../../../assets/splash.png'),
      social: Social.InstagramStories,
      url: screenshot,
      type: 'image/png',
      appId: applicationId,
      title: 'Test Title',
    });
  };
  1. Watch AppStore open

Expected behavior

Based on documentation, I was under the impression that I can share directly to Instagram. The behavior would be:

  • on press of button in app, share menu opens or share to instagram menu opens
  • choose "share" button from menu and Instagram will open with Store or Post based on settings above.

Actual behavior

  • It opens the AppStore directly.
    image

  • Video: https://github.com/user-attachments/assets/aa3ff13e-f55e-440a-9ef2-a1e864045615

I am able to work around by using Share.open:

    await Share.open({
      // backgroundImage: require('../../../assets/splash.png'),
      // social: Social.InstagramStories,
      url: screenshot,
      type: 'image/png',
      // appId: applicationId || 'com.identafly.dev',
      title: 'Test Title',
    });
  };

Environment

    "expo": "^50.0.17",
    "expo-media-library": "~15.9.2",
    "react-native-share": "^10.2.1",
    "react-native-view-shot": "3.8.0",
    "react-native": "0.73.6",

react-native-share

Version: "^10.2.1"

lucksp avatar Aug 21 '24 21:08 lucksp

+1

iveshenry18 avatar Aug 30 '24 07:08 iveshenry18

    shareOptions = {
      social: Share.Social.INSTAGRAM_STORIES,
      appId: 'appId',
      backgroundImage: `data:image/jpeg;base64,${base64Image}` as string,
      backgroundBottomColor: '#ffffff' as string,
      backgroundTopColor: '#000000' as string,
    };
    
    Perhaps it should be transmitted in base64

Pupsentiy avatar Sep 02 '24 05:09 Pupsentiy

I had the same issue and figured out that it's not an issue with this package, just a matter of setting up your iOS LSApplicationQueriesSchemes permissions, as described in the docs. For an Expo app, that means adding the following to your app.json:

    "ios": {
      "infoPlist": {
        "LSApplicationQueriesSchemes": [
          "instagram-stories",

iveshenry18 avatar Sep 02 '24 10:09 iveshenry18

+1 got the exact same issue... Not using Expo btw. Followed the steps that where provided in the docs, but wasn't able to build the app afterwards...

XavegX367 avatar Sep 04 '24 14:09 XavegX367

+1 got the exact same issue... Not using Expo btw. Followed the steps that where provided in the docs, but wasn't able to build the app afterwards...

Interesting. What values do you currently have under LSApplicationQueriesSchemes in your info.plist?

iveshenry18 avatar Sep 04 '24 22:09 iveshenry18

+1 got the exact same issue... Not using Expo btw. Followed the steps that where provided in the docs, but wasn't able to build the app afterwards...

Interesting. What values do you currently have under LSApplicationQueriesSchemes in your info.plist?

I just copied the rows from the docs:

	 <key>LSApplicationQueriesSchemes</key>
      <array>
        <string>whatsapp</string>
        <string>mailto</string>
        <string>instagram</string>
        <string>instagram-stories</string>
        <string>fb</string>
        <string>facebook-stories</string>
      </array>

And tried to share something to Instagram / Facebook

XavegX367 avatar Sep 05 '24 07:09 XavegX367

I just copied the rows from the docs:

	 <key>LSApplicationQueriesSchemes</key>
      <array>
        <string>whatsapp</string>
        <string>mailto</string>
        <string>instagram</string>
        <string>instagram-stories</string>
        <string>fb</string>
        <string>facebook-stories</string>
      </array>

And tried to share something to Instagram / Facebook

very strange; once I got my Info.plist right, I didn't have any more issues.

My only thought then would be to make sure the request is correct. In my case, I use:

await Share.shareSingle({
    social: Social.InstagramStories,
    stickerImage: stickerPng,
    backgroundImage: bgPng,
    appId,
});

iveshenry18 avatar Sep 05 '24 07:09 iveshenry18

very strange; once I got my Info.plist right, I didn't have any more issues.

My only thought then would be to make sure the request is correct. In my case, I use:

await Share.shareSingle({
    social: Social.InstagramStories,
    stickerImage: stickerPng,
    backgroundImage: bgPng,
    appId,
});

At the moment I have made it like this:

  const shareToPlatform = async (socialPlatform: string) => {
    try {
      const localImagePath = await downloadImage(images[0].url);

      const shareOptions = {
        title: 'Share via',
        url: `file://${localImagePath}`,
        type: 'image/jpeg',
        social: socialPlatform,
      };

      await Share.shareSingle(shareOptions);
    } catch (error) {
      console.error(`Error sharing post to ${socialPlatform}:`, error);
    }
  };

  const openPlatform = async () => {
    if (platform === 'Facebook') {
      await shareToPlatform(Social.Facebook);
    } else if (platform === 'Instagram') {
      await shareToPlatform(Social.Instagram);
    } else {
      console.warn('Unsupported platform');
    }
  };

And on Android sharing to Instagram is working flawless, while on iOS it just opens the App store...

XavegX367 avatar Sep 05 '24 08:09 XavegX367

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open

github-actions[bot] avatar Nov 18 '24 02:11 github-actions[bot]