How to create a react native ios share extension app

允我心安 提交于 2019-12-12 10:41:19

问题


I want my react-native app to be available for share from Whatsapp, Skype, Photos.. I tried using react-native-share-extension but it is only showing the extension in the Safari browser.

How to implement the sharing feature in applications other than Safari in react-native for iOS?


回答1:


This is because the default setup if this package is for sharing urls to your app.

You need to change/extend/rewrite NSExtensionActivationRule in Config.plist of your share extension and stay with react-native-share-extension package. Read more about this key from author and in Apple docs directly.

So you can rewrite entirely rule to apply e.g. pdf files (as said in apple docs):

<key>NSExtensionAttributes</key>
<dict>
    <key>NSExtensionActivationRule</key>
    <string>
        {extensionItems = ({
            attachments = ({
                registeredTypeIdentifiers = (
                    "com.adobe.pdf",
                    "public.file-url"
                );
            });
        })}
    </string>
</dict>

All keys for NSExtensionActivationRule could be found here.




回答2:


I fixed it by adding this in info plist

<dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>



回答3:


By default, react-native-share-extension only allows the sharing of urls from browsers. There is some extra configuration to add if you want to tell the system to show your extension when sharing a url that you seem to have missed.

For iOS, you simply need to update the Info.plist file and add the following:

<key>NSExtensionAttributes</key>
<dict>
  <key>NSExtensionActivationRule</key>
  <dict>
    <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
    <integer>1</integer>
  </dict>
</dict>

To confirm it's done correctly, this setting should then be displayed in XCode and allow a successful build:



来源:https://stackoverflow.com/questions/53134531/how-to-create-a-react-native-ios-share-extension-app

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