Reputation: 39
I am trying to send a picture from my phonegap app as an attachment using the email composer with attachments phone gap plugin. I cannot get it to work however.
I have tried two separate methods. The first is to use the Phonegap camera api's to pass an imageURI to email composer. The code for this is below:
function camera1()
{
navigator.camera.getPicture(sendEmail, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI});
function sendEmail(imageURI) {
window.plugins.emailComposer.showEmailComposer("Test","Test","[email protected]","","",true,imageURI)
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
This method launches the iphone camera app and allows me to take a picture. However, as soon as I hit the 'use' button I get the following error in my xcode debug console:
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!
The second method I have tried to use is to save the image to local storage and then pass it as a variable to email composer. I also implemented a notification event in this method as the previous error message made me think that the email composer plugin was trying to open too quickly after the camera event (pure guess based on 'Warning: Attempt to present on while a presentation is in progress!') The code is as follows:
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","[email protected]","","",true,photo);
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
The problem with this code is that the camera doesn't launch at all. Nothing happens when I click the button. Not even anything in the debug console.
To further complicate matters I tried just opening a basic email composer event to see that I had implemented the plugin properly. When not trying to attach a picture the email composer at least opens with my subject and body filled in. It doesn't fill in any recipients though. The code is:
function camera()
{
window.plugins.emailComposer.showEmailComposer("Test","Test","[email protected]","","",true,"")
}
My question is what am I doing wrong?
Upvotes: 0
Views: 3789
Reputation: 91
i don't know if this is the cause of your error but the path of your attachment shoud be somewhat like ["/var/mobile/Applications/351............F3/yourapp.app/www/images/yourimage.png"]
Upvotes: 0
Reputation: 5795
toRecipients
, ccRecipients
, bccRecipients
, and attachments
parameters should be arrays, but you're passing them as strings.
window.plugins.emailComposer.showEmailComposer("Test", "Test", ["[email protected]"], [], [], true, [imageURI]);
do it like this and try again.
Upvotes: 1