Attach a PDF file to email - Swift
You are passing wrong mimeType
to addAttachmentData()
. Use application/pdf
instead of pdf
.
Attached PDF to email in Swift, but the PDF is not decoded
OK, I figured it out. Dropbox URLs, at least for PDFs if not everything, include a dl=0 tag to indicate downloading permission. In order to send a PDF through an app, you have to change the dl=0 to dl=1. Then everything works as it should.
So there would be no change to the code above. The change is in my Parse browser where I list my files.
Eli
Attach the pdf file into mail automatically after saving
The Swift 3.0 code below is worked great!
let pdfFilePath = "path to file.pdf"
let url = NSURL.fileURL(withPath: pdfFilePath)
let activityVC = UIActivityViewController(activityItems: ["My Pdf File",url], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)
swift pdf file not attaching to an email
Because your file is put into the user's temporary folder, I do not think it will be accessible from the a NSBundle
method. That said, if you are writing the NSData
to disk in the temporary folder and then directly emailing it, you may want to consider just passing that variable (pdfData
) to the mail controller like:
mail.addAttachmentData(pdfData, mimeType: "application/pdf", fileName: "file.pdf")
Related Topics
Launching Phone/Email/Map Links in Wkwebview
Uitapgesturerecognizer Programmatically Trigger a Tap in My View
Becomefirstresponder Not Working in iOS 8
How to Properly Use Class Extensions in Swift
Dispatchqueue Crashing with Main.Sync in Swift
How to Draw Inside the Black Edges in iOS Sdk with Opengl Es
How to Set Mdm Payload's "Identity" in Ipcu
How to Add Watermark on a Exist Image
Swift: Type Must Implement Protocol and Be a Subclass of Given Class
Uislider Setmaximumtracktintcolor in iOS 7.1
Swift: Return Array of Type Self
Uisearchcontroller Not Redisplaying Navigation Bar on Rotate
How to Generate All Possible Combinations
Object-C/iOS :How to Use Asynchronous to Get a Data from Url
How to Pop View Controller to One of the Previous View Controllers in Swift
Swiftui Transitions: Scale from Some Frame - Like iOS Homescreen Is Doing When Opening an App