Problem
While sending the image files as a attachment using EmailDialog the receive image is empty.
Reproducible Steps
1. Execute the project that was attached
2. Install the application to some iOS device
3. Send an email to you
4. Check your inbox - the image received is empty
Sample Code
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
win1.open();
var emailDialog = Titanium.UI.createEmailDialog();
emailDialog.subject = 'Take a look at this great app I found!';
emailDialog.toRecipients = [];
emailDialog.messageBody = "u";
var f = Ti.Filesystem.getFile('off.png');
if(f.exists())
{
emailDialog.addAttachment(f);
}
else
{
emailDialog.messageBody = "test";
}
emailDialog.open();
Associated HelpDesk Ticket
http://appc.me/c/APP-353882
This is not a problem on our SDK, This happens as the PNG files in the resources folder are being transfered to iOS device ,the build process compresses the file for optimization and as a result of which any PNG file in the app's resources folder that you may send as a email attachment won't show up on a computer , but can be seen through any iOS device. NOTE : THIS ONLY HAPPENS FOR PNG FILES AND NO OTHER TYPES OF FILE HAVE ANY PROBLEM ... AND HAPPENS FOR PNG FILES SHIPPED ALONG WITH THE APP, IT SHOULDN'T CREATE A PROBLEM IF YOU ARE TYRING TO SEND A PNG FILE FROM THE PHOTO LIBRARY INSIDE THE PHONE.
blog post that explains the whole process . http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized-pngs.html
Further commentary: To turn off the png compression would be a speed hit to the app in general, possibly to file size as well, and is generally frowned upon. Emailing resources that were compiled into the app is the exception, not the norm. Solutions: 1) Save the png under a different extension so it doesn't get compressed at build time 2) Use a different file type 3) Open the png, resize it to itself, and save the new, uncompressed image and send that. All of these solutions to this odd edge case can be done completely in javascript.
//workaround code : Titanium.UI.setBackgroundColor('#000'); var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); win1.open(); var emailDialog = Titanium.UI.createEmailDialog(); emailDialog.subject = 'Take a look at this great app I found!'; emailDialog.toRecipients = []; emailDialog.messageBody = "u"; //var f = Ti.Filesystem.getFile('off.png'); <- Remove this line var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'convert.PNG'); //<-- insert file.write(Ti.UI.createImageView({image:'off.PNG',}).toImage()); //<-- insert if(f.exists()) { emailDialog.addAttachment(f); } else { emailDialog.messageBody = "test"; } emailDialog.open();
This is a known issue with the way Apple preprocesses PNG files for inclusion into an app. Use the workaround in the ticket for png files from the Resources directory.
Closing ticket as invalid.