簡體   English   中英

如何將文檔文件傳遞給 UIActivityViewController 即共享表

[英]How to pass a Document File to UIActivityViewController i.e. Share Sheet

我有一個 iOS 應用程序,它生成一個 CSV 文件並將其保存到設備的工作文檔目錄中。 現在,當用戶按下按鈕時,會顯示 UIActivityViewController 共享表,它允許您打開向其他應用程序發送數據。

我的問題是如何將此 CSV 文件傳遞​​到共享表。 我知道如何使用文本和圖像來實現這一點,但不完全確定如何使其與 CSV 文件一起使用。 最終結果是我希望此文件在從共享表中選擇的任何電子郵件客戶端中顯示為附件。

這是我用來打開文檔(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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM