我正在尝试使用带有附件电话间隙插件的电子邮件编辑器从我的电话间隙应用程序发送图片作为附件。但是我无法让它工作。
我尝试了两种不同的方法。第一种方法是使用 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:]: unrecognized selector sent to instance 0x1dd9d6a0 2013-01-06 17:57:50.906 Saffron Housing Mobile App[1203:907] EmailComposer - Cannot set TO recipients; error: -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd9d6a0 2013-01-06 17:57:50.914 Saffron Housing Mobile App[1203:907] -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd1abf0 2013-01-06 17:57:50.916 Saffron Housing Mobile App[1203:907] EmailComposer - Cannot set attachments; error: -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd1abf0 2013-01-06 17:57:51.524 Saffron Housing Mobile App[1203:907] Warning: Attempt to present on while a presentation is in progress!
我尝试使用的第二种方法是将图像保存到本地存储,然后将其作为变量传递给电子邮件编辑器。我还在这个方法中实现了一个通知事件,因为之前的错误消息让我认为电子邮件编辑器插件在相机事件之后试图打开得太快(纯粹基于“警告:在演示文稿正在进行时尝试演示”) !')代码如下:
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,"")
}
我的问题是我做错了什么?
最佳答案
toRecipients
、ccRecipients
、bccRecipients
和 attachments
参数应该是数组,但您正在传递它们作为字符串。
window.plugins.emailComposer.showEmailComposer("Test", "Test", ["test@gmail.com"], [], [], true, [imageURI]);
这样做然后再试一次。
关于javascript - 带有附件的电子邮件编辑器 Phonegap 插件无法在 iOS 中使用 imageURI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14185197/