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

Nothing is caught in the listener when using continueInApp()

Open raquelmsmith opened this issue 4 years ago • 12 comments

I'm trying to share directly from Safari into the app without using a share sheet. In share.tsx I have

import React, { useState, useEffect } from "react"
import ShareMenu, { ShareMenuReactView } from "react-native-share-menu"

function ShareScreen() {

  ShareMenuReactView.continueInApp()
  return <></>
}

export default ShareScreen

In app.tsx, I have a listener and handler that work on Android.

 // Catch shared information

  const handleShare = useCallback((item: SharedItem) => {
    if (!item || !item.data) {
      return
    }
    navigationRef?.current?.navigate("import", { url: item.data })
  }, [])

  useEffect(() => {
    !initializing && ShareMenu.getInitialShare(handleShare)
  })

  useEffect(() => {
    const listener = ShareMenu.addNewShareListener(handleShare)

    return () => {
      listener.remove()
    }
  }, [initializing])

But when I share from Safari in iOS, handleShare never gets called. The listener never "hears" the data getting passed. The app does open properly. What am I missing? How do I properly use continueInApp()?

raquelmsmith avatar Oct 04 '21 16:10 raquelmsmith

@raquelmsmith did you get this to work properly? I have it set up but when trying to share it the app does not open.

ghost avatar Oct 22 '21 13:10 ghost

I follow this link and has the same problem too: https://github.com/meedan/react-native-share-menu/issues/106#issuecomment-782034472

  • The problem is the mismatch between share extension' surlscheme and AppDelegate.m's urlscheme. if ([urlString hasPrefix:urlScheme]) { My problem solved.

solominh avatar Oct 22 '21 13:10 solominh

@solominh Unfortunately I was not able to get the project built after modifying this file.

ghost avatar Oct 22 '21 22:10 ghost

@raquelmsmith What is in your Info.Plist file of this extension? We had the same problem and we were missing the :// in the HostAppURLScheme field.

kubik369 avatar Nov 08 '21 17:11 kubik369

We had the same issue which was caused by the ordering of the CFBundleURLSchemes entries in our Info.plist. Once they were ordered so the full bundleId came first, it started to work.

A trick is to set a project-level user-defined config setting, then reference in your main plist and app extension plist.

        <key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLName</key>
			<string>$(PARENT_APP_BUNDLE_IDENTIFIER)</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>$(PARENT_APP_BUNDLE_IDENTIFIER)</string>
				<string>someOtherScheme</string>
			</array>
		</dict>
	</array>

Then in your share extension Info.plist

<key>HostAppBundleIdentifier</key>
<string>$(PARENT_APP_BUNDLE_IDENTIFIER)</string>
<key>HostAppURLScheme</key>
<string>$(PARENT_APP_BUNDLE_IDENTIFIER)://</string>

dburdan avatar Nov 08 '21 22:11 dburdan

Hey @raquelmsmith were you able to resolve your problem? I'm also in this roadblock

jojonarte avatar Apr 09 '22 15:04 jojonarte

I haven't been using continueInApp() so I can't help with this issue, sorry.

raquelmsmith avatar Apr 10 '22 02:04 raquelmsmith

Oddly enough my setup worked after a clean and restart :P

jojonarte avatar Apr 11 '22 02:04 jojonarte

For us, it was that we weren't also calling ShareMenuReactView.dismissExtension() after the call to continue in app. This was putting Safari into a bad state. By calling this method right after continueInApp() we were able to reset the modal state in Safari.

JohnGrisham avatar Aug 24 '22 20:08 JohnGrisham

please help... kindly explain i am trying to send extraData in my app from share by using continueInApp but i can't receive that data in my app. can anyone please help. @JohnGrisham @jojonarte @raquelmsmith @dburdan @gilsonviana-modus @solominh @kubik369

ShareMenuReactView.data().then(item => {
     ShareMenuReactView.continueInApp({
       anykey:"anyValue",
       data: item.data[0].data,
       mimeType: item.data[0].mimeType,
     });
   
   });

asadd-irfan avatar Sep 01 '22 09:09 asadd-irfan

We were facing the same issue. Our problem was that the main target and the share extension target were not in a properly named group for our debug build. The group HAS TO BE EXACTLY named group.YOUR_APP_BUNDLE_ID, so if your main app is com.app.your, it needs to be group.com.app.your and if you have a debug build with bundle id com.app.your.debug you need another group group.com.app.your.debug

filipgerat avatar Mar 10 '23 12:03 filipgerat

@filipgerat are you ShareMenu.getInitialShare? The issue is that getInitialShare works but listeners don't fire off. my groups settings are properly setup but the listener doesn't kick off. Hence I have an app://OpenURL route that calls getInitialShare when it is opened.

devYonz avatar May 10 '23 18:05 devYonz