5

I have created a react-native app using expo. Now I am looking for share-extension to the app to import CSV data from email attachment to my app.

I have tried npm package but that does not work for me(I was not able to build my project with that npm package in Xcode)

I think react-native or expo does not have any share API

In this picture, you can see how he got the option to import data into the app.

I understand that without share extension API, I think react-native and Expo both are useless because you can create the app but you don't expand it.

Looking for the solution or any other alternate solution.

Rutul Patel
  • 663
  • 2
  • 10
  • 23
  • i think this package will solve your problem https://github.com/alinz/react-native-share-extension – Ciprian B Nov 01 '18 at 22:09
  • @CiprianB To be very honest I don't have much experience with Objective - C. – Rutul Patel Nov 01 '18 at 22:10
  • @CiprianB Are you able to explain in detail or is there any video of doing this thing? – Rutul Patel Nov 01 '18 at 22:11
  • I saw the description provided by author but did not understand anything. – Rutul Patel Nov 01 '18 at 22:12
  • At this moment you don't have alternative for sharing data with your app. You need to install that npm, and you have all the steps described very well. PS. Keep in mind, with this approach you will edit the native apps(ios + android) – Ciprian B Nov 01 '18 at 22:17

1 Answers1

7

I'm afraid this is not possible with expo.

First of all, are you looking for a way to create your own extension, or do you just want your app to be in the "open with list" that you have in the screenshot on the right? (Sharing and "open with" are two distinct things.)

If you just want your app to be listed in the standard "open with list", you do not need to use github.com/alinz/react-native-share-extension since it serves a different purpose. To quote the repo:

This is a helper module which brings react native as an engine to drive share extension for your app.

So with the package you can use react native to create your own share extension

To get your app into the "open with list", you need to go to target settings and change it according to the screenshot (example for MS word). Read more about it here. However, I'm afraid you won't be able to do this with expo without ejecting.

enter image description here

How to get the url of the file in react-native? You need to make sure that libRCTLinking.a is in the Link Binary with Libraries in Xcode (it'll probably be there already). And then you can follow the docs and call Linking.getInitialURL to get the file url. Then it really depends on what you want to do with the file. If you need something complicated, you'll likely need to write native code. If you just want to upload the file to some server, then you can make use of blob support that was added to RN 0.54 in this commit. An example of how to use the blob support is here.

vonovak
  • 1,555
  • 2
  • 14
  • 28
  • I like your answer and thanks for your most useful information. I just want, my app in "open with list". I was miss understood by share extension. – Rutul Patel Nov 01 '18 at 22:50
  • Thanks for your answer! Is that possible to handle incoming file from react native? and am I able to build ios app after ejecting and editing the Info as described in screenshot ? – Rutul Patel Nov 02 '18 at 01:27
  • @RutulPatel I have expanded the answer. Well, yes, you should be able to build the app after ejecting. – vonovak Nov 02 '18 at 08:51
  • from where should I able to handle that incoming data to the app from react native? – Rutul Patel Nov 02 '18 at 13:05
  • @RutulPatel please see the docs link in the answer: https://facebook.github.io/react-native/docs/linking – vonovak Nov 02 '18 at 14:03
  • So, I tried this thing. but now I have minor confusion, I detached from expo but now there is no mean to handle this by Linking. because if I make changes am I able to build project with expo again or I have to do that manually from Xcode ? – Rutul Patel Nov 04 '18 at 23:29
  • Hey @vonovak, Now I am getting this kind of URL `'exp:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv'` do you know how can I read file ? – Rutul Patel Nov 05 '18 at 18:22
  • I got this error [Unhandled promise rejection: Error: File 'file:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv' isn't readable.] – Rutul Patel Nov 05 '18 at 18:25
  • hard to say, I think you can open a new question for this and provide more info – vonovak Nov 05 '18 at 18:28
  • I know you are an expert. can you please take look here.. https://stackoverflow.com/questions/53160752/how-to-get-file-from-uri-expo-react-native – Rutul Patel Nov 05 '18 at 19:16
  • Do you have any idea why my file is copied into private storage?. – Rutul Patel Dec 16 '18 at 22:06