问题
I Have implemented an iPhone application in Phone Gap using jQuery Mobile.
As the part of my app i need to send an email by click on a Button 'MAIL'
For that i added EmailComposer plug in.
added EmailComposer.js in www folder and
added EmailComposer.H and .M file in Resources folder of application.
I implemented the code as follows
<script type="text/javascript" src="EmailComposer.js"></script>
<script type="text/javascript" charset="utf-8">
function SendEmail() {
alert('XXXXX');
window.plugins.emailComposer.showEmailComposer("SubjectXXX","PlainTextBody---",
"recipientName,recipientName", "ccRecipient", "bccRecipient",false);
}
</script>
<a href="#" onclick="SendEmail(); return false;" data-icon="arrow-r" data-iconpos="left" class="ui-btn-left" >Send</a>
Mail composer view displays all is well.
Now I need to Atach a file to this email how to attach a file
Can any one guide me the way
tahnks in advance.
回答1:
I did it this way:
var attachPath;
var attachFile= new Array();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("MyAppFolder", {
create: true
},
function(directory) {
console.log("Final 63" + directory.fullPath);
attachPaths = directory.fullPath;
var attachPath=attachPaths.slice(7,attachPaths.length);
var directoryReader = directory.createReader();
directoryReader.readEntries(function(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
attachFile[i] =attachPath + "/" + entries[i].name;
}
console.log(attachFile);
},
function (error) {
alert(error.code);
});
});
}, function(error) {
alert("can't even get the file system: " + error.code);
});
Now pass attachFile to mailcomposer
window.plugins.emailComposer.showEmailComposerWithCallback(null,
"Get an Estimate",
"Body",
["mail_id"],
[],
[],
true,
attachFile
);
Hope this helps you!!!!!
来源:https://stackoverflow.com/questions/11341503/how-to-attach-a-file-to-the-mail-in-iphone-phonegap-jquery-mobile