Reputation: 796
I'm building an IOS app in ionic
that captures media (photo, video, audio) and ran into a quite confounding issue today. I'm using the following 3 methods (on MediaCapture
):
captureImage()
captureVideo()
captureAudio()
The only one that doesn't work is captureImage()
and I can't, for the life of me, figure out why. Side note: I was able to use camera.getPicture()
but I'd like to use MediaCapture
for all 3 media types (and it doesn't make sense why I can't).
Here are some details:
ionic
: 3.15.2Cordova
: 7.1.0I'm running the app on my device using ionic cordova run ios -l -c -s
.
private media: object = {
'image': 'captureImage',
'video': 'captureVideo',
'audio': 'captureAudio'
};
function captureMedia(media) {
console.log('capturing');
const options: CaptureImageOptions = {
limit: 1
};
this.mediaCapture[this.media[media]](options)
.then(
(data: MediaFile[]) => console.log(JSON.stringify(data)),
(err: CaptureError) => console.error(JSON.stringify(err))
);
}
captureMedia('image'); // CRASHES!!
captureMedia('audio'); // WORKS!
captureMedia('video'); // WORKS!
No output. No warnings. No console output. Just kaput!
I feel like I'm missing something here but I can't see what it is. Can anyone help?
Upvotes: 2
Views: 655
Reputation: 796
So, I ended up attempting to run this on my device from Xcode and finally got a useful error message! It turns out, my config.xml
was missing one property for privacy permissions.
This was the one that was missing:
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryAddUsageDescription">
<string>Allow photo library access.</string>
</edit-config>
Remember, you'll also need descriptions for the following (which I had):
NSCameraUsageDescription
NSMicrophoneUsageDescription
NSPhotoLibraryUsageDescription
Cheers!
Upvotes: 1