Make the selected data in the app a CSV file and
Call Mailer,
I would like to attach it to an email and send it to you.
I don't know what to do.
Even if I looked it up on my own, there was only a way to load the CSV file, so
I'm struggling.
If you don't mind, please let me know.
Thank you for your cooperation.
Add **************
What should I do if I want to attach two separate csv files?
The class MFMailComposeViewController
makes it easy to call iPhone mailers from the app.(You can also set up an attachment, so I think it's perfect for your question.)
func sendMailWithCSV(subject: String, message: String, csv:[String]]) {
letmailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate=self
mailVC.setSubject(subject)
mailVC.setMessageBody (message, isHTML:false)
mailVC.addAttachmentData(toCSV(csv)
.dataUsingEncoding (NSUTF8 StringEncoding, allowLossyConversion: false)
, mimeType: "text/csv"
, fileName: "data.csv")
self.presentViewController(mailVC, animated:true){}
}
Also, toCSV
which creates CSV strings from a multidimensional array of strings was written with reference to the following page.
http://ja.wikipedia.org/wiki/Comma-Separated_Values
func toCSV(a:[[String]]])->String{
US>return join("\n", a.map {join(", ", $0.map {ein
contains(e) {contains("\n\"", ", $0)}
"\"" + e.stringByReplacingOccurrencesOfString("\"", withString:"\"\"", options:nil, range:nil)+"\":e
})}) + "\n"
}
© 2024 OneMinuteCode. All rights reserved.