【发布时间】:2014-08-19 09:50:46
【问题描述】:
我正在使用以下插件从 iphone phongeap 应用程序(使用 ionic)发送电子邮件:https://github.com/katzer/cordova-plugin-email-composer
一切正常,除非我尝试附加保存到设备的 pdf 文件:当电子邮件界面打开时,我可以看到附加的 pdf(称为 test.pdf),但是当电子邮件到达收件人时,有没有PDF。相反,有一个附加的 txt 文件,但没有任何内容。
如果我去 window.replace(pdf 的路径),PDF 会打开,所以我确定 PDF 被保存并且路径是正确的。在阅读了https://github.com/katzer/cordova-plugin-email-composer/issues/33 之后,我还尝试删除路径 start (file://) 并将其替换为 (relative://) 但没有用。非常感谢您对此的任何意见:以下是相关代码:
var doc = new jsPDF();
doc.text(20, 20, 'HELLO!');
doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'This is a PDF document generated using JSPDF.');
doc.text(20, 50, 'YES, Inside of PhoneGap!');
var pdfOutput = doc.output();
console.log( pdfOutput );
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile("test.pdf", {create: true}, function(entry) {
var fileEntry = entry;
console.log(entry);
$scope.filepath = fileEntry.toURL();
$scope.filepath = $scope.filepath.replace('file\:\/\/', 'relative://');
$scope.emailer($scope.filepath);
// window.location.href = $scope.filepath;
entry.createWriter(function(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
console.log("writing to file");
writer.write( pdfOutput );
}, function(error) {
console.log(error);
});
}, function(error){
console.log(error);
});
},
function(event){
console.log( evt.target.error.code );
});
$scope.emailer = function(file) {
alert(file);
window.plugin.email.open({
to: ['info@appplant.de'],
subject: 'Congratulations',
body: '<h1>Happy Birthday!!!</h1>',
attachments: [file]
});
【问题讨论】:
标签: ios cordova email ionic-framework