Reputation: 2224
I am developing an hybrid app for Android and for IOS using ionic.
While opening the Camera from Android is working perfectly, but I am not able to open an camera from IOS device.
I install respective plugin for that
cordova plugin add cordova-plugin-camera
.
next I added the ng-cordova.js
into index.html
before the cordova.js
line.
Also in app.js
i include angular.module('starter', ['ionic', 'ngCordova']
In the Controller.js added $cordovaCamera
my code as
navigator.camera.getPicture(onSuccess,onFail, {
quality:90
destinationType:Camera.DestinationType.DATA_URL,
sourceType:Camera.PictureSourceType.CAMERA,
allowEdit:false,
encodingType:Camera.EncodingType.JPEG,
popoverOptions:CameraPopoverOptions,
saveToPhotoAlbum:true,
correctOrientation:true
})
function onSuccess(imageURI){
$rootScope.$broadcast("ShowAttachmentModal",imageURI);
}
function onSuccess(message){
alert('Failed'+message);
}
This code work perfectly in Android but not working in IOS while to open camera.
Upvotes: 0
Views: 2225
Reputation: 461
@MartinP, instead of ngCordova, which is being deprecated, see if you can use the replacement library Ionic-Natve (http://ionicframework.com/docs/v2/native/camera/).
Then try this code instead.
function takePicture() {
var opts = {
quality: 90,
encodingType: $cordovaCamera.EncodingType.JPEG,
destinationType: $cordovaCamera.DestinationType.DATA_URL,
correctOrientation: true,
allowEdit: true,
targetWidth: 300,
targetHeight: 300
};
$cordovaCamera.getPicture(opts).then(function (imageData) {
$rootScope.$broadcast("ShowAttachmentModal",imageData);;
}, function (err) {
$log.error(err);
});
}
The Cordova plugin is the same. You'll need to inject $cordovaCamera into your controller. Once it works, then you can play around with the options. As you may be aware, the DATA_URL option returns a Base64-encoded string. So to set it as an image's source, you'll need to prepend imageData with 'data:image/jpeg;base64,'
.
Upvotes: 1