Hello,
I’ve implemented a popup window that lets a user choose between getting a photo from the camera or gallery. When choosing the camera option the camera loads, but when choosing the photo gallery option the gallery isn’t opened, instead the camera is!
Also if I do take a photo it doesn’t seem to come back as I don’t see the alert(), and the popup doesn’t close. I’ve borrowed code from the ionic camera example to get it to this point. I thought it might be an options problem so I have tried different combinations of Camera.PictureSourceType.PHOTOLIBRARY and navigator.camera.PictureSourceType.PHOTOLIBRARY too but the same issue remains.
Any ideas?
Snippets of code is below:
Photo Controller
.controller('PhotoCtrl', function($scope, $ionicPopup, Camera){
$scope.showPopup = function() {
$scope.data = {}
var myPopup = $ionicPopup.show({
title: 'Add a photo',
subTitle: 'Choose from Camera or Gallery',
scope: $scope,
buttons: [
{
text: '<i class="icon ion-camera"></i>',
type: 'button-stable',
onTap: function(e) {
$scope.capturePhoto();
return;
}
},
{
text: '<i class="icon ion-image"></i>',
type: 'button-stable',
onTap: function(e) {
$scope.chooseFromGallery();
return;
}
}
]
});
myPopup.then(function(res) {
console.log('Tapped!', res);
});
};
$scope.capturePhoto = function(){
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
alert('got camera photo');
}, function(err) {
console.err(err);
}, {
destinationType : Camera.DestinationType.DATA_URL,
quality: 75,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false
});
};
$scope.chooseFromGallery = function(){
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
alert('got photo');
}, function(err) {
console.err(err);
}, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false,
destinationType : Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
});
};
})
Camera Factory
.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;
}
}
}])