且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用共享扩展程序从其他APP到Swift中的APP读取附件文件中的字符串,而不直接共享字符串?

更新时间:2023-01-01 22:22:16

首先,在共享扩展名的info.plist中,您必须设置附件的类型以及扩展名可以得到多少

First of all, in info.plist of your share extension you have to set what type of attachments and how many your extension can get

示例:

    <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsImageWithMaxCount</key>
                <integer>10</integer>
                <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
                <integer>1</integer>
                <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
                <integer>1</integer>
            </dict>
        </dict>

您可以找到所有的键扩展名首先获取附件时,您需要检查其类型(即您希望接受的附件). 然后,在didSelectPost()中,您可以获取该附件并对其进行处理(如果需要的话,可以将其存储在您的应用中).

When your extension recives attachment first you need to check it for type(is it what you are expecting to recive). And then, in didSelectPost() you can get that attachment and do something with it (maybe store it in your app if that's what you want).

这里是一篇关于照片扩展名的好文章

Here is nice article about shere extension for photos