Reputation: 43
created a UIActivityViewController to share my CSV file.
I can send the email but I can not add attachments csv file
This is my code:
if ((directorys) != nil) {
// Path
let directories:[String] = directorys!;
let dictionary = directories[0];
let plistfile = "bpmonitor.csv"
let plistpath = dictionary.stringByAppendingPathComponent(plistfile);
println("\(plistpath)")
csvString.writeToFile(plistpath, atomically: true, encoding: NSUTF8StringEncoding, error: nil)
let activityViewController = UIActivityViewController(
activityItems: ["body", NSData.dataWithContentsOfMappedFile(plistpath) as NSData],
applicationActivities: nil)
activityViewController.setValue("Your email Subject", forKey: "subject")
activityViewController.completionHandler = {(activityType, completed:Bool) in
if !completed {
println("cancelled")
return
}
if activityType == UIActivityTypeMail {
}
if activityType == UIActivityTypePostToTwitter {
println("twitter")
}
if activityType == UIActivityTypeMail {
println("mail")
}
}
Upvotes: 1
Views: 1779
Reputation: 4955
Try adding the file URL as the attachment:
let activityViewController = UIActivityViewController(
activityItems: [NSURL(fileURLWithPath: plistpath)],
applicationActivities: nil)
Upvotes: 1