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

Fatal error if re-do share (iOS)

Open ruslanaplid opened this issue 4 years ago • 8 comments

My Share.js

const Share = () => {

	useEffect(() => {
		ShareMenuReactView.data().then(({mimeType, data}) => {
			_.defer(() => {
				ShareMenuReactView.continueInApp({data});
			});
		});
	}, []);

	return null;
};

First sharing - ok Second sharing - Fatal error Third - ok

ShareExtension/ReactShareViewController.swift:59: Fatal error: Unexpectedly found nil while unwrapping an Optional value func loadExtensionContext() -> NSExtensionContext { return extensionContext! }

ruslanaplid avatar Jun 17 '21 10:06 ruslanaplid

I'm getting the exact same error. I noticed that if I put in a debugger break point just under func loadExtensionContext() -> NSExtensionContext { The problem stops happening. This leads me to believe that for whatever reason, the extension context WILL load, it just takes time.

As a very, very hacky workaround, I have changed the function to look like:

func loadExtensionContext() -> NSExtensionContext {
    // Sleep for 300 ms
    let ms = 1000
    usleep(useconds_t(300 * ms))
    return extensionContext!
  }

I realize this is terrible - the problem is that the extension context doesn't seem to load correctly the second time around. The solution is probably to wait for the context to be ready and timeout if it doesn't ready within one second or something.

I don't speak Swift, so I can't really fix it better than this though.

Rob117 avatar Jun 30 '21 06:06 Rob117

Note that the problem only seems to happen on an actual device.

Rob117 avatar Jun 30 '21 06:06 Rob117

Sorry to hijack this thread, but I need help with actually using continueInApp() - wondering if any of you here who seem to be using it successfully can lend a hand: #155

raquelmsmith avatar Oct 04 '21 17:10 raquelmsmith

@ruslanaplid I'm trying to fix this by comment this line

https://github.com/meedan/react-native-share-menu/blob/9ede6840dd7ddc01d8a686c605a1cfbdf69512c8/ios/Modules/ShareMenuReactView.swift#L20

it has guard, so every time attachViewDelegate is called it will always use previous delegate instead of using new delegate, that's why ExtensionContext not working.

RZulfikri avatar Oct 20 '21 15:10 RZulfikri

@RZulfikri did it actually fix the issue?

ghost avatar Oct 27 '21 14:10 ghost

@gilsonviana-modus it works for me, try my PR.

RZulfikri avatar Oct 27 '21 23:10 RZulfikri

Also fixed it for me.

Would be great to merge the PR or find some better solution though.

durdevic avatar Dec 08 '21 17:12 durdevic

Screenshot 2023-07-25 at 15 12 06 Solution fix this

tamdvyounetgroup avatar Jul 25 '23 08:07 tamdvyounetgroup