3

I am creating a Cordova application in Windows(due to unavailability of Mac) using JQuery for IOs and remote building on Phonegap cloud. but the issue is when i try getting image from camera of my iPhone(Os v-11.3) through cordova-plugin-camera the app crashes.

config.xml:

<plugin name="cordova-plugin-camera" spec="~2.1.1">
        <variable name="CAMERA_USAGE_DESCRIPTION" value="App want to access your camera" />
        <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App want to access your camera to upload images" />

 </plugin>

 <platform name="ios">
        <icon height="57" platform="ios" src="www/res/icon/ios/icon.png" width="57" />
........
........
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
              <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>

    </platform>

JS:

 function accessCamera(){
        var options =  setOptions(Camera.PictureSourceType.CAMERA);
        getPic(options);
    }
function setOptions(srcType) {
        var options = {
            // Some common settings are 20, 50, and 100
            quality: 50,
            destinationType: Camera.DestinationType.FILE_URI,
            // In this app, dynamically set the picture source, Camera or photo gallery
            sourceType: srcType,
            encodingType: Camera.EncodingType.JPEG,
            mediaType: Camera.MediaType.PICTURE,
            allowEdit: true,
            correctOrientation: true  //Corrects Android orientation quirks
        }
        return options;
    }



  function getPic(options){
        console.log(Camera.PictureSourceType);
        console.log("SourceTye: "+options.sourceType);
        try{
            navigator.camera.getPicture(function cameraSuccess(imageUri) {
               // $('#main_img').attr('src', imageUri);
               setAndUploadPic(imageUri);

            }, function cameraError(error) {
            console.debug("Unable to obtain picture: " + error, "app");

            }, options);
        }catch(err){
           // $('#exp').text(err.message);
        }

    }

but as soon as I access camera my app crashes.

mr debug
  • 189
  • 1
  • 2
  • 16

3 Answers3

1

If you run in simulator on xcode and take a look on consolle you are able to see what happend. In my experience problem is related to plist setting of NsCameraUsageDescription, in consolle exist a specific error for this when app crash. Try to add this lines to plugin.xml of camera plugin instead of that posted above:

 <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
     <string>For take user photo and upload photos.</string>
 </config-file>

 <preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
 <config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
     <string>For upload photos.</string>
 </config-file>

 <config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
     <string>need location access to find things nearby</string>
 </config-file>
Frix33
  • 1,231
  • 10
  • 27
  • yes you are right about simulator but i wasn't having that at my end so was facing difficulty debugging it . but according to docs of particular plugin they mentioned to do it that way – mr debug Apr 16 '18 at 10:58
0

Please update your camera plugin and check

<plugin name="cordova-plugin-camera" spec="2.4.1" />
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
0

Please remove updated version of particular plugin and remove version number

<plugin name="cordova-plugin-camera">

It will run file. Your plugin is causing issue.

Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55