Hi all,
I am experiencing an interesting issue when attempting to create an export a CSV from data in my iOS app (swift 2.0 in Xcode 7). Below is a description of the pattern of failure. Any assistance with this would be greatly appreciated!
When using UTF8 String Encoding, and sending out the email, my CSV attachment opens perfectly when opened from webmail (i.e. gmail, yahoo mail etc using a browser: chrome, safari, firefox, etc). However when opening the CSV attachment through an email account set up in Microsoft Outlook, the attachment becomes nonsensical:
ezW
w JiHbcZ`..7'5*^y^tSCE*^y^ySE'
[ ‑+l!sk![ 6*'z
h:wl~h'Ym
g "im1*^
{‑r ]0:0‑X&{T-j;S
g# m
g5 wS
g# m
g6JV+58&x:0‑X&{a'u8&{mxe*^y^tSD-j;R%ggM4JZ)SNtY+-x (:{t
When i change the encoding to UTF16, now the email accounts set up in Microsoft Outlook download and open the attachment perfectly; however the webmail accounts (email through browser) download and open the attachment with the correct information, however it looks like it wasn't treated as a CSV and everything is in one column:
Study Name Results
Study Parameters:
Machine Type,Machine Name
Current Speed,500.0
Max Speed,750.0
Units, Units of Production (e.g pounds) / min
All time counts are in seconds
Downtime 2 Start Time, Downtime 2 End Time ,
2, 6,
Speed: 500.0 Start, Speed: 500.0 Stop,
0.0, 6.0,
Waste Amount:
0
(everywhere there is a comma should be in a new column)
Key block of code:
let csvString = generateExportString()
let data = csvString.dataUsingEncoding(NSUTF8StringEncoding) <--- this is where i've been changing the type of string encoding used
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
if (MFMailComposeViewController.canSendMail()) {
mailComposer.setSubject("Stroud Line Study - \(study!.name)-Results")
mailComposer.setMessageBody("Stroud Line Study Results are attached", isHTML: false)
mailComposer.addAttachmentData(data!, mimeType: "text/csv", fileName: "\(study!.name)-Results.csv") <-- not sure if this is the best mimeType
}
self.presentViewController(mailComposer, animated: true, completion: nil)
Thank you for all your help in advance!