Expensify / react-native-share-menu

A module for React Native that adds your app to the share menu of the device
MIT License
639 stars 235 forks source link

Fatal error if re-do share (iOS) #135

Open ruslanaplid opened 3 years ago

ruslanaplid commented 3 years ago

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! }

Rob117 commented 3 years ago

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 commented 3 years ago

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

raquelmsmith commented 2 years ago

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

RZulfikri commented 2 years ago

@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.

ghost commented 2 years ago

@RZulfikri did it actually fix the issue?

RZulfikri commented 2 years ago

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

durdevic commented 2 years ago

Also fixed it for me.

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

tamdvyounetgroup commented 1 year ago

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