我正在尝试使用带有附件手机间隙插件的电子邮件作曲家从我的phonegap应用程序发送图片作为附件。然而,我无法让它发挥作用。
我尝试了两种不同的方法。第一种是使用Phonegap相机api将imageURI传递给电子邮件作曲家。代码如下:
function camera1()
{
navigator.camera.getPicture(sendEmail, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI});
function sendEmail(imageURI) {
window.plugins.emailComposer.showEmailComposer("Test","Test","test@gmail.com","","",true,imageURI)
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
此方法启动iphone相机应用程序并允许我拍照。但是,只要我点击“使用”按钮,我的xcode调试控制台就会出现以下错误:
2013-01-06 17:57:50.741 Saffron Housing Mobile App [1203:907] - [_ NSCFString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0x1dd9d6a0 2013-01-06 17:57:50.906 Saffron Housing Mobile App [1203:907] EmailComposer - 无法设置TO收件人;错误: - [ _NSCFString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0x1dd9d6a0 2013-01-06 17:57:50.914 Saffron Housing Mobile App [1203:907] - [_ NSCFString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0x1dd1abf0 2013-01-06 17:57:50.916 Saffron Housing Mobile App [1203:907] EmailComposer - 无法设置附件;错误: - [ _NSCFString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0x1dd1abf0 2013-01-06 17:57:51.524 Saffron Housing Mobile App [1203:907]警告:在演示过程中尝试演示!
我尝试使用的第二种方法是将图像保存到本地存储,然后将其作为变量传递给电子邮件编辑器。我还在这个方法中实现了一个通知事件,因为之前的错误消息让我觉得电子邮件编辑器插件在摄像机事件后试图打开得太快(基于'警告:在演示文稿正在进行时尝试出现)的纯猜测!')代码如下:
function camera1()
{
navigator.camera.getPicture(sendAlert, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI});
localStorage.setItem('photo', imageURI);
function sendAlert()
navigator.notification.confirm('Send Picture?',sendEmail,'Send Picture?','Yes,No')
function sendEmail(1) {
var photo = localStorage.getItem('photo')
window.plugins.emailComposer.showEmailComposer("Test","Test","test@gmail.com","","",true,photo);
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
此代码的问题在于相机根本无法启动。单击按钮时没有任何反应。甚至在调试控制台中都没有。
为了使问题更加复杂,我尝试打开基本的电子邮件编辑器事件,看看我是否正确实现了插件。当不试图附加图片时,电子邮件作曲家至少打开我的主题和正文填写。但它不会填写任何收件人。代码是:
function camera()
{
window.plugins.emailComposer.showEmailComposer("Test","Test","test@gmail.com","","",true,"")
}
我的问题是我做错了什么?
答案 0 :(得分:1)
toRecipients
,ccRecipients
,bccRecipients
和attachments
参数应该是数组,但您将它们作为字符串传递。
window.plugins.emailComposer.showEmailComposer("Test", "Test", ["test@gmail.com"], [], [], true, [imageURI]);
这样做,然后再试一次。
答案 1 :(得分:0)
我不知道这是否是您的错误的原因,但您的附件的路径应该有点像 [“/ var / mobile / Applications / 351 ........... .F3 / yourapp.app / www / images / yourimage.png“]