【问题标题】:How to pass a Document File to UIActivityViewController i.e. Share Sheet如何将文档文件传递给 UIActivityViewController 即共享表
【发布时间】:2015-09-07 04:30:46
【问题描述】:

我有一个 iOS 应用程序,它生成一个 CSV 文件并将其保存到设备的工作文档目录中。现在,当用户按下按钮时,会显示 UIActivityViewController 共享表,允许您打开将数据发送到其他应用程序。

我的问题是如何将此 CSV 文件传递​​到共享表。我知道如何使它与文本和图像一起使用,但不完全确定如何使它与 CSV 文件一起使用。最终结果是我希望此文件在从共享表中选择的任何电子邮件客户端中显示为附件。

【问题讨论】:

    标签: ios swift csv ios-sharesheet


    【解决方案1】:

    这是我用来打开文档(word、pdf 等)的代码。应该适合你...

    @IBAction func openDocument(sender: AnyObject)
    {
        let interactionController = UIDocumentInteractionController(URL: documentURL)
    
        // (build your document's URL from its path in the Documents directory)
    
        interactionController.delegate = self
    
    
        // First, attempt to show the "Open with... (app)" menu. Will fail and
        // do nothing if no app is present that can open the specified document
        // type.
    
        let result = interactionController.presentOpenInMenuFromRect(
            self.view.frame,
            inView: self.view,
            animated: true
        )
    
    
        if result == false {
    
            // Fall back to "options" view:
    
            interactionController.presentOptionsMenuFromRect(
                self.view.frame,
                inView: self.view,
                animated: true)
        }
    
        // DONE
    }
    

    【讨论】:

    • 超级酷,谢谢芽。这有效,除了一件事,它似乎适用于某些程序而不适用于其他程序。这是为什么?例如,当我选择 GMail 时,GMail 客户端和作曲家打开,但文件没有附加到它。另一方面,当我选择我的一个文件传输程序时,它适用于这种情况。
    • 还有一件事,为什么 Apple Mail Client 没有显示在 Document Selection 列表中?
    • 我不认为你可以配置太多;据我所知,系统几乎根据文件类型和安装的应用程序确定工作表的内容。
    • 对了,我贴的代码基本上是苹果的示例代码。
    • 我认为您可能是对的,我只是在控制台中查看我的日志文件,它显示调用了正确的扩展名等...但是插件使内容无效。所以我想我能做的不多。无论如何,我仍然会接受您的回答,因为它在技术上是正确的,但我猜由于 Apple 的 API,我无法控制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    相关资源
    最近更新 更多