Share extension react native - expo

六月ゝ 毕业季﹏ 提交于 2019-12-30 10:12:05

问题


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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/51642385/share-extension-react-native-expo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!