I am able to use the camera plugin from cordova-plugin-camera to take pictures from my mobile device but am having a problem specifying the Camera options.
I tried the following in my controller to see what keys the Camera object had:
$ionicPlatform.ready(function() {
for (var key in Camera) {
alert(key);
}
});
And it just returns the getPicture() method. The other keys such as 'EncodingType' or 'MediaType' are missing. I went and threw logs in the Camera.js in the camera library when it populates the cameraExport object and everything is getting populated properly (EncodingType and etc are all available). It's just not available when it reaches my controller.
When I try to reference Camera.EncodingType.JPEG - I get "Cannot read property JPEG of undefined."
I have tried uninstalling the plugin and re-installing it via the git url and also tried the org.apache.cordova.camera method (after uninstalling). I updated the ionic lib. Created new projects in hopes that it was just a configuration mistake.
Here is an example controller I threw together that has the issue as well:
.controller('PhotoCtrl', function($scope, $state, $ionicPlatform, Camera) {
$ionicPlatform.ready(function() {
alert(JSON.stringify(Camera)); // This just shows empty brackets: {}
});
$scope.getPhoto = function() {
try {
// Errors with this alert - if I take it out, it will allow me to take a picture
alert(Camera.EncodingType.JPEG);
Camera.getPicture().then(function(photoUri) {
alert(photoUri);
}, function(err) {
console.err(err);
},
{
// Again, if I remove the Camera.EncodingType.JPEG, it will save the picture
encodingType: Camera.EncodingType.JPEG,
// These don't work either. Almost like the options aren't being applied.
correctOrientation: true,
saveToPhotoAlbum: true
});
}
catch(err) {
// Throws the "Cannot read property JPEG of undefined."
alert(err);
}
};
})
Any ideas?
Please let me know if I can provide any more information.
Thanks in advance!
It turns out my Camera object was a factory made object. I just forgot to add the constants from navigator.camera.
Doh!
.factory('Camera', ['$q', function($q) {
return {
getPicture: function(options) {
var q = $q.defer();
navigator.camera.getPicture(function(result) {
// Do any magic you need
q.resolve(result);
}, function(err) {
q.reject(err);
}, options);
return q.promise;
},
// Forgot the following
EncodingType: navigator.camera.EncodingType,
DestinationType: navigator.camera.DestinationType,
MediaType: navigator.camera.MediaType,
PictureSourceType: navigator.camera.PictureSourceType,
PopoverArrowDirection: navigator.camera.PopoverArrowDirection,
Direction: navigator.camera.Direction
}
}])