iOS MFMailComposeViewController not attaching file
Summary:
I am using the below snippet for sending an email from my app to an email address.
Below implementation works fine in case of configuration as below :
iOS Device : Any
iOS Version : Below 12
However in case of iOS 12 and iPhone XR, I am not able to see attached file in mail.
This is reproducible only on iPhone XR with iOS 12+. In case of other devices having iOS 12 the issue is not reproducible.
func sendMail(filePath:String){
let toRecipients = user@domain.com
let subject = “Email Subject”
let formatter = DateFormatter()
formatter.dateFormat="dMMMyyyy";
let dateString = formatter.string(from: Date())
let userName :String = “ABC”
var bodyText1: String?
var bodyTextLocation: String?
bodyText1 = "<html><body><br> " + “Date:” + dateString
bodyText1 = bodyText1! + "<br><br>------------------------------<br>"
+ “Contact us for additional help” + "</body></html>"
let body = "<html><body><br><br><br><br><br>" + UIDevice.current.model + "<br> " + "</body></html>"
var bodyText2 : String?
bodyText2 = body + bodyText1!
let mail = configuredMailComposeViewController(recipients: toRecipients, subject: subject, body: bodyText2!, isHtml: true, images: nil)
if let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath))
{
print("File data loaded.")
let logFileName = (filePath as NSString).lastPathComponent
mail.addAttachmentData(fileData, mimeType: "text/plain", fileName: logFileName)
}
presentMailComposeViewController(mailComposeVC: mail)
}
func presentMailComposeViewController(mailComposeVC : MFMailComposeViewController) {
if MFMailComposeViewController.canSendMail(){
self.rootVC.present(mailComposeVC, animated: true, completion: nil)
}else{
//Error
}
}
Steps to Reproduce:
Use iOS 12+ and iPhone XR
Use above code snippet
Expected Results:
File should get attached in email body.
Actual Results:
File is not getting attached in email body.
Note : This gets reproduced randomly.
Version/Build:
iOS 12+
Configuration used:
iPhone XR
iOS 12+
ios swift mfmailcomposeviewcontroller
add a comment |
Summary:
I am using the below snippet for sending an email from my app to an email address.
Below implementation works fine in case of configuration as below :
iOS Device : Any
iOS Version : Below 12
However in case of iOS 12 and iPhone XR, I am not able to see attached file in mail.
This is reproducible only on iPhone XR with iOS 12+. In case of other devices having iOS 12 the issue is not reproducible.
func sendMail(filePath:String){
let toRecipients = user@domain.com
let subject = “Email Subject”
let formatter = DateFormatter()
formatter.dateFormat="dMMMyyyy";
let dateString = formatter.string(from: Date())
let userName :String = “ABC”
var bodyText1: String?
var bodyTextLocation: String?
bodyText1 = "<html><body><br> " + “Date:” + dateString
bodyText1 = bodyText1! + "<br><br>------------------------------<br>"
+ “Contact us for additional help” + "</body></html>"
let body = "<html><body><br><br><br><br><br>" + UIDevice.current.model + "<br> " + "</body></html>"
var bodyText2 : String?
bodyText2 = body + bodyText1!
let mail = configuredMailComposeViewController(recipients: toRecipients, subject: subject, body: bodyText2!, isHtml: true, images: nil)
if let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath))
{
print("File data loaded.")
let logFileName = (filePath as NSString).lastPathComponent
mail.addAttachmentData(fileData, mimeType: "text/plain", fileName: logFileName)
}
presentMailComposeViewController(mailComposeVC: mail)
}
func presentMailComposeViewController(mailComposeVC : MFMailComposeViewController) {
if MFMailComposeViewController.canSendMail(){
self.rootVC.present(mailComposeVC, animated: true, completion: nil)
}else{
//Error
}
}
Steps to Reproduce:
Use iOS 12+ and iPhone XR
Use above code snippet
Expected Results:
File should get attached in email body.
Actual Results:
File is not getting attached in email body.
Note : This gets reproduced randomly.
Version/Build:
iOS 12+
Configuration used:
iPhone XR
iOS 12+
ios swift mfmailcomposeviewcontroller
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59
add a comment |
Summary:
I am using the below snippet for sending an email from my app to an email address.
Below implementation works fine in case of configuration as below :
iOS Device : Any
iOS Version : Below 12
However in case of iOS 12 and iPhone XR, I am not able to see attached file in mail.
This is reproducible only on iPhone XR with iOS 12+. In case of other devices having iOS 12 the issue is not reproducible.
func sendMail(filePath:String){
let toRecipients = user@domain.com
let subject = “Email Subject”
let formatter = DateFormatter()
formatter.dateFormat="dMMMyyyy";
let dateString = formatter.string(from: Date())
let userName :String = “ABC”
var bodyText1: String?
var bodyTextLocation: String?
bodyText1 = "<html><body><br> " + “Date:” + dateString
bodyText1 = bodyText1! + "<br><br>------------------------------<br>"
+ “Contact us for additional help” + "</body></html>"
let body = "<html><body><br><br><br><br><br>" + UIDevice.current.model + "<br> " + "</body></html>"
var bodyText2 : String?
bodyText2 = body + bodyText1!
let mail = configuredMailComposeViewController(recipients: toRecipients, subject: subject, body: bodyText2!, isHtml: true, images: nil)
if let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath))
{
print("File data loaded.")
let logFileName = (filePath as NSString).lastPathComponent
mail.addAttachmentData(fileData, mimeType: "text/plain", fileName: logFileName)
}
presentMailComposeViewController(mailComposeVC: mail)
}
func presentMailComposeViewController(mailComposeVC : MFMailComposeViewController) {
if MFMailComposeViewController.canSendMail(){
self.rootVC.present(mailComposeVC, animated: true, completion: nil)
}else{
//Error
}
}
Steps to Reproduce:
Use iOS 12+ and iPhone XR
Use above code snippet
Expected Results:
File should get attached in email body.
Actual Results:
File is not getting attached in email body.
Note : This gets reproduced randomly.
Version/Build:
iOS 12+
Configuration used:
iPhone XR
iOS 12+
ios swift mfmailcomposeviewcontroller
Summary:
I am using the below snippet for sending an email from my app to an email address.
Below implementation works fine in case of configuration as below :
iOS Device : Any
iOS Version : Below 12
However in case of iOS 12 and iPhone XR, I am not able to see attached file in mail.
This is reproducible only on iPhone XR with iOS 12+. In case of other devices having iOS 12 the issue is not reproducible.
func sendMail(filePath:String){
let toRecipients = user@domain.com
let subject = “Email Subject”
let formatter = DateFormatter()
formatter.dateFormat="dMMMyyyy";
let dateString = formatter.string(from: Date())
let userName :String = “ABC”
var bodyText1: String?
var bodyTextLocation: String?
bodyText1 = "<html><body><br> " + “Date:” + dateString
bodyText1 = bodyText1! + "<br><br>------------------------------<br>"
+ “Contact us for additional help” + "</body></html>"
let body = "<html><body><br><br><br><br><br>" + UIDevice.current.model + "<br> " + "</body></html>"
var bodyText2 : String?
bodyText2 = body + bodyText1!
let mail = configuredMailComposeViewController(recipients: toRecipients, subject: subject, body: bodyText2!, isHtml: true, images: nil)
if let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath))
{
print("File data loaded.")
let logFileName = (filePath as NSString).lastPathComponent
mail.addAttachmentData(fileData, mimeType: "text/plain", fileName: logFileName)
}
presentMailComposeViewController(mailComposeVC: mail)
}
func presentMailComposeViewController(mailComposeVC : MFMailComposeViewController) {
if MFMailComposeViewController.canSendMail(){
self.rootVC.present(mailComposeVC, animated: true, completion: nil)
}else{
//Error
}
}
Steps to Reproduce:
Use iOS 12+ and iPhone XR
Use above code snippet
Expected Results:
File should get attached in email body.
Actual Results:
File is not getting attached in email body.
Note : This gets reproduced randomly.
Version/Build:
iOS 12+
Configuration used:
iPhone XR
iOS 12+
ios swift mfmailcomposeviewcontroller
ios swift mfmailcomposeviewcontroller
edited Jan 1 at 6:27
etoUser
asked Jan 1 at 5:10


etoUseretoUser
1
1
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59
add a comment |
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993133%2fios-mfmailcomposeviewcontroller-not-attaching-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993133%2fios-mfmailcomposeviewcontroller-not-attaching-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Add breakpoint and check if you are getting fileData. Also check filePath.
– Venk
Jan 1 at 5:12
do you see the "File data loaded." line in your Xcode console log?
– Michael Dautermann
Jan 1 at 6:59