0

我正在尝试使用带有附件电话间隙插件的电子邮件编辑器从我的 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 - 无法设置收件人;错误:-[ _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,"")

        }

我的问题是我做错了什么?

4

2 回答 2

1

toRecipients, ccRecipients, bccRecipients, 和attachments参数应该是数组,但您将它们作为字符串传递。

window.plugins.emailComposer.showEmailComposer("Test", "Test", ["test@gmail.com"], [], [], true, [imageURI]);

这样做,然后再试一次。

于 2013-01-06T18:24:24.777 回答
0

我不知道这是否是您的错误的原因,但您的附件路径应该有点像["/var/mobile/Applications/351............F3/yourapp.app /www/images/yourimage.png"]

于 2013-03-22T10:00:21.653 回答