Massimo Sarzi
Massimo Sarzi

Reputation: 33

ionic v1 cordova-plugin-camera problems with ios

compiling my old ionic project with Xcode 9.2 I have problems with cordova-plugin-camera. This code:

$cordovaCamera.getPicture(options).then(function (imageData) {

                var image = document.getElementById('myImage');
                image.src = imageData;
});

Was perfect with Xcode 8, but now I can't see the preview of the image in img tag ...

Of course I set the content-security-policy:

<meta http-equiv="Content-Security-Policy" content="default-src * gap:;font-src 'self' data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; media-src *; img-src * filesystem: data:">

What else can I do???

Massimo

Upvotes: 0

Views: 162

Answers (2)

milmal
milmal

Reputation: 551

Probably too late, but my solution to this problem was to:

  1. Add this inside <platform name="ios"> to my config.xml:

    <edit-config target="NSCameraUsageDescription" file="platforms/ios/ios.json" mode="merge"><string>need camera access to take pictures</string></edit-config>
    
  2. Add "Privacy - Camera Usage Description" to the Information Property List in appname-info.plist in xcode.

Also:

navigator.camera.getPicture(this.cameraCallback);

And then I have a callback:

cameraCallback(imageData) { 
   myImg.src = 'data:image/jpeg;base64,' + imageData;
}

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53301

Try changing the img-src to

img-src 'self'  * filesystem: data: content:

Upvotes: 0

Related Questions