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

getInitialShare call back is empty array in ios

Open EswarSatti opened this issue 2 years ago • 9 comments

In Ios callback is {"data": []} in android callback is {"data": "https://youtu.be/kOvOWqzCRq8", "mimeType": "text/plain"}

EswarSatti avatar Feb 14 '23 14:02 EswarSatti

yes i have same issue ,please anyone help on this

vigneshwarram avatar Feb 16 '23 08:02 vigneshwarram

The same for me. Has somebody resolved the issue?

szu2 avatar May 10 '23 13:05 szu2

Same for me

zubyrbutt avatar May 27 '23 14:05 zubyrbutt

Is there anyone solved this problem?

Seration avatar Jul 04 '23 22:07 Seration

Found a solution that works for me (initial testing in iOS emulator only) based on this comment, which identifies that the example project code doesn't work as expected.

For iOS, you can do something like the following:

  useEffect(() => {
    ShareMenuReactView.data().then(({ data }) => {
      // data is a list of objects shaped like { data: ..., mimeType: ...}
      // Initially only caring about the first item, and disregarding cross-platform compatibility below:
      const sharedItem = data[0];
      setSharedData(sharedItem.data);
      setSharedMimeType(sharedItem.mimeType);
    });
  }, []);

freethejazz avatar Jul 10 '23 02:07 freethejazz

I found my solution in the configuration. I miss a part to include which is in HostAppURLScheme. Whatever you add in your app info.plist URL scheme, pls double-check that you ve added it with :// at the end of your HostAppURLScheme in your share extension info.plist

<key>HostAppBundleIdentifier</key>
<string>com.github.meedaan.ReactNativeShareMenuExample</string>
<key>HostAppURLScheme</key>
<string>ShareMenuModule://</string>
<key>NSExtension</key>

After I added it, I run pod install, build the app in xcode and then delete and re-install the app. Then I saw the data in the console.

Ps: I read the data with @freethejazz example...

Seration avatar Jul 21 '23 22:07 Seration

Had a similar oversight as @Seration: I forgot to add the "HostAppBundleIdentifier" in the Sharingextension plist file and only got {data: null} #as a result.

After adding it I can now read the data with this setup:

when app starts up on Share Event useEffect(() => { ShareMenu.getInitialShare(handleShare) }, [])

when app is already running useEffect(() => { const listener = ShareMenu.addNewShareListener(handleShare) return () => { listener.remove() } }, [])

aLotlBit avatar Aug 15 '23 16:08 aLotlBit

Yeap, HostAppBundleIdentifier ==> you app bundle id and use group.<you app bundle id>

anatooly avatar Sep 06 '23 09:09 anatooly

To clarify @anatooly comment. Avoid putting $(APP_BUNDLE_ID) in the SharingExtension plist. Just hardcode the string

<key>HostAppBundleIdentifier</key> <string>com.some.bundleid</string>

hichemBAALI avatar Apr 22 '24 19:04 hichemBAALI