Hi! I’ve been developing an app in Ionic and until now I have tested it just in an Android device. But since yesterday I’ve been testing it in an iOS device thanks to DevApp. It works fine, but the problem comes when I try to take a picture using camera plugin of Ionic Native. I’m able to open the camera and take the picture, but when I click “Use Photo” the app just stops working.
The function below is the one I use to take the picture. In Android it works fine.
var filename = this.name + " " + this.surname + ".jpg";
var options = {
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
targetWidth: 900,
targetHeight: 600,
correctOrientation: true
}
this.camera.getPicture(options).then((imageData) => {
var new_path;
alert(imageData);
if (this.platform.is('android')) {
new_path = imageData.substring(imageData.indexOf('s'));
} else {
new_path = imageData.replace(/^.*[\\\/]/, '');
}
alert(new_path);
alert(imageData);
this.residency_image = new_path;
this.authService.uploadImage(this.residency_image, filename);
this.register();
}, (err) => {
this.failedAlert("Internal error", "Error while taking the picture");
});
}
I’ve also been searching about this problem and I’ve added the following to config.xml and to MyApp-Info.plist but I still have the problem.
config.xml
<plugin name="cordova-plugin-camera" spec="^4.7.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value=" " />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value=" " />
</plugin>
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
<string>need camera access to take pictures</string>
</edit-config>
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to get pictures from there</string>
</edit-config>
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to save pictures there</string>
</edit-config>
MyApp-Info.plist
<key>NSCameraUsageDescription</key>
<string>need camera access to take pictures</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>need photo library access to get pictures from there</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>need location access to find things nearby</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>need photo library access to save pictures there</string>
Thank you for your help!