Expensify / react-native-share-menu

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

Crash when share from some apps. [iOS] #113

Open Shchepotin opened 3 years ago

Shchepotin commented 3 years ago

ShareExtension works fine is most cases, but when I try share url from some apps, for example Mango, ShareExtension crash.

I debug ShareExtension and get error in https://github.com/meedan/react-native-share-menu/blob/master/ios/ShareViewController.swift#L163.

I think it's happen because Mango app share few attachments (image, url) and ShareViewController return only first attachment (image). Can we return all (I think this is the right way) or first attachment which supported by app type identifiers? My app work only with URL and plain text and don't handle image.

mdmush commented 3 years ago

I'm facing this issue as well. Does anybody have solution for this?

yannikw23 commented 3 years ago

Same here...Has anyone found a solution? Happens for Twitter, LinkedIn, Reddit (and others) for me. Safari works fine.

At first I suspected that the max memory limit of an extension has been reached causing the extension to close automatically. Not too sure about that one though, also hard to debug...

In debug mode on a real device it always closes automatically (from any app, also from safari). In release mode it does not provide any information via Xcode.

yannikw23 commented 3 years ago

Ok, I inspected the issue using the MacOS Console tool to get detailed device logs. This is the fatal error crashing the extension:

default 13:12:49.844917+0200 kernel EXC_RESOURCE -> <EXTENSION_NAME>[13182] exceeded mem limit: InactiveHard 120 MB (fatal)

This is a pain, as I don't know how to reduce the required memory...I use AWS Amplify and a couple of other frameworks which seem to be very memory intensive. And unfortunately I need them for my application.

@Gustash do you have any idea how to tackle this? Maybe reducing image size (I display a couple in my extension's custom view) would also help? Any help is highly appreciated!

Sharisu commented 3 years ago

Same problem.

I tried debbug with the XCode Profiler and found that the extension on the simulator consumes 3 times more memory than the main application. But there are much fewer components in it. On a real device, the situation is almost the same.

In my case it always falls (9 times out of 10) when I try share inside Soundcloud. Always memory issue on load

yannikw23 commented 3 years ago

@Sharisu I've been struggling with this for a while now and currently I am using a very hacky work around:

I created a MemoryWarningHandler component which is imported in my share extension. On memory warning it calls ShareMenu.continueInApp() to handle the sharing in there. That way at least the user has the chance to complete the sharing transaction.

const MemoryWarningHandler = (props: MemoryWarningProps) => {
  const { onMemoryWarningCallback } = props;

  useEffect(() => {
    // Listen for AppState memoryWarning event
    AppState.addEventListener('memoryWarning', (state) => {
      console.warn('Triggered memoryWarning. Initiating continueInApp');
      // call callback on warningEvent triggered
      onMemoryWarningCallback();
    });

    return () => {
      AppState.removeEventListener('memoryWarning', () => {});
    };
  }, []);

  return null;
};

This is very far from ideal, but it gets the job done (at the expense of user experience)... Maybe it helps you as well.

@Gustash Are there any updates on this? @caiosba maybe?

alexpluto commented 3 years ago

This is still an issue for us as well.

Strangely this is predominately affecting when sharing from Instagram app.

@Gustash have you been able to look into this at all? Thank you!

yannikw23 commented 3 years ago

@alexpluto Do you currently have a workaround for this issue?

alexpluto commented 3 years ago

@yannikw23 this workaround didn't work for us and we still have no other solutions... :(

Sharisu commented 3 years ago

@yannikw23 nice trick! This made the situation better, but did not completely solve the problem. Thanks for idea :)

Kumskov-dev commented 3 years ago

@yannikw23 I have the same issue when I'm trying to share some data from Instagram app . ShareExtension is crashed immediately in most cases, adding "memoryWarning" listener doesn't solve my problem, the crash is still exist.

yannikw23 commented 3 years ago

@Sharisu - yeah, same here. It made the situation bearable, but definitely still far from ideal.

@Kumskov-dev I see. Yes, the crash still appears but we catch that in the main app then since we call continueInApp().

It's a bit frustrating...Is any of you sufficiently advanced in native dev to investigate this further?

Otherwise, can we hope for support? @Gustash (sorry to keep bringing it up, it's just a major hurdle)

alexpluto commented 3 years ago

Or maybe @caiosba (seems like another big contributor here). Any help would be super helpful guys! Thank you in advance.

caiosba commented 3 years ago

I just maintain the Android version... @Gustash do you have any chance to look into it?

We accept PRs from the community too, if anyone is able to fix it.

alexpluto commented 3 years ago

@Gustash I was just wondering if you ever managed to look at this issue? It's still affecting us now unfortunately :(

eranga-akva commented 2 years ago

Got the same issue, for example in ios gmail app, opening a url inside the gmail app (not in the browser), and trying to share the url using share menu crashes the share modal. I see the following in xcode. Screenshot 2021-12-15 at 12 10 07

RDR96 commented 1 year ago

I think all this is related to how the default share popup is displayed to the user. See this #256

I was having the same issues with some apps, I realized is related with how the preview content is displayed.