UIActivityViewController - 将文件 url 从 myApp 共享到 myApp

问题描述 投票:0回答:0

我会做什么?

我希望能够在我自己的应用程序中共享文件 url,例如 whatsapp,即:

  • 打开我的应用程序
  • 从 myApp 分享内容
  • 从列表中选择我的应用程序

我在做什么?

从 Xcode 自行生成的应用程序开始

我猜关键词是

CFBundleDocumentTypes
。 所以我加了

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array/>
            <key>CFBundleTypeName</key>
            <string>All Files</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.data</string>
            </array>
        </dict>
    </array>

Info.plist
。 通过这样做,myApp 能够从外部接收文件(例如从文件应用程序)。

然后我在

ViewController

中添加
@IBAction func share(_ sender: Any)
    {
        let url = Bundle.main.url(forResource: "blank", withExtension: "pdf")!
        let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
        
        // iPad
        if let popover = activityViewController.popoverPresentationController
        {
            popover.sourceView = view
            popover.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.maxY, width: 0, height: 0) //center bottom
        }
        
        activityViewController.isModalInPresentation = true
        
        present(activityViewController, animated: true)
    }

链接到

Button
.

问题

通过单击共享按钮,myApp 不会出现在列表中。

有什么好笑的?它适用于模拟器 - Xcode 14.3 RC 2.

ios swift uiactivityviewcontroller
© www.soinside.com 2019 - 2024. All rights reserved.