gpt4 book ai didi

ios - 通过 UIActivityViewController 共享 csv 文件

转载 作者:行者123 更新时间:2023-11-28 06:36:53 25 4
gpt4 key购买 nike

我正在尝试使用 UIActivityViewController 共享一个 csv 文件。
我想通过电子邮件和其他应用程序(例如 Telegram)共享。
通过 Telegram 可以正确共享文件,但使用电子邮件时,电子邮件没有附件。
另外,csv 文件没有扩展名,我应该设置 MIME 类型吗?怎么办?

 @IBAction func shareSheet(sender: AnyObject) {

let firstActivityItem = "Hi, here is the csv file"

//do i really need this? what for?
let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")!

let csv : NSData! = NSData(contentsOfFile: NSTemporaryDirectory() + "export.csv")

let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem, csv], applicationActivities: nil)

//set the email title
activityViewController.setValue(firstAcxtivityItem, forKey: "subject")


self.presentViewController(activityViewController, animated: true, completion: nil)
}

最佳答案

这是我用来通过邮件编辑器发送 CSV 的代码

let csvString = "Your CSV String"
let subject = "Subject of your email"
let fileName = "CSV Filename.csv"

let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
composeVC.setSubject(subject)

if let csvData = csvString.data(using: String.Encoding.utf8) {
composeVC.addAttachmentData(csvData, mimeType: "text/csv", fileName: fileName)
}

self.present(composeVC, animated: true, completion: nil)

关于ios - 通过 UIActivityViewController 共享 csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38896434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com