简体   繁体   中英

Camera plugin crashes Cordova app on iOS but not on Android

I developed an app on Cordova 4.2.0 for Android and iOS. After successfully signing the app for Android and testing all functionality on Galaxy Note 10.1, I copied the www-code to my MacBook and built it for my iPad 4 (iOS 8.3).

The app works perfectly on both devices but one thing doesn't:

1.) Camera on Android is opened on clicking the Camera-Button and I can shoot a photo. After selecting "Use" the photo gets uploaded to the server and the screen flips back to the overview, showing the photo.

2.) On iOS the whole app is crashing on clicking the Camera-Button (when the camera should appear). So the camera is not even opened. On debugging console I don't get any output as the debugger looses connection to the app immediately.

What could be the problem? Following I put my code for this functionality:

//get photo from camera

function getPhoto(source) {
    var options;
    if(source == 0)
    {
        var src = 'library';
    }
    else if(source == 1)
    {
        var src = 'camera';
    }

    sendImage(src, 'img1');
}

//upload photo to server

function sendImage(src, imagenr) {

    // Set the image source [library || camera]
    src = (src == 'library') ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA;

    // Aquire the image -> Phonegap API
    navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: src, destinationType : Camera.DestinationType.DATA_URL});

    // Successfully aquired image data -> base64 encoded string of the image file
    function success(imageData) {
        if(db.getItem("siteaudit") != ""){
            var url = db.getItem("saurl")+"section_faults_image_upl.php";
        }else{
            var url = db.getItem("url")+"section_faults_image_upl.php";
        }
        var params = {};
        params.uid = db.getItem('uid');
        params.sid = db.getItem('location');
        params.guid = db.getItem('faultID');
        params.file = imageData;

        // send the data

        $.ajax({
            type: "POST",
            url: url,
            data: params,
            async: false,
            username: db.getItem("user"),
            password: db.getItem("pass"),
            xhrFields: { withCredentials: true },
            dataType: "html",
            success: function(data, status, object){
                var body = object.responseText;
                //alert(body);

                var filepath = db.getItem("url_base")+body;
                //alert(filepath);
                db.setItem(imagenr, filepath);
                $('#'+imagenr).attr('src',filepath);
                $('#a'+imagenr).attr('href',filepath).vanillabox({
                    animation: 'none',
                    closeButton: false,
                    keyboard: false,
                    loop: false,
                    preferredWidth: 640,
                    preferredHeight: 480,
                    repositionOnScroll: true,
                    type: 'image',
                    adjustToWindow: 'both'
                });

                if(imagenr == "img6")
                {
                    $('#uplImgCamera').addClass("ui-disabled");
                    $('#uplImgGallery').addClass("ui-disabled");
                }
            },
            error: function(e){
                navigator.notification.alert('Status 184: '+e.status+' '+e.statusText, function(){}, 'Error...', 'Close');
            }
        });
    }

    function fail(message) { alert(message); }
}

Thank you in advance for any idea on what could go wrong...

EDIT :

Just some additional information after debugging excessive with breakpoints:

The problem seems to be in this line:

navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: Camera.PictureSourceType.CAMERA, destinationType : Camera.DestinationType.DATA_URL});

and I also tried it with popoverOptions:

navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: Camera.PictureSourceType.CAMERA, destinationType : Camera.DestinationType.DATA_URL, popoverOptions: new CameraPopoverOptions(300,300,100,100,Camera.PopoverArrowDirection.ARROW_ANY)});

Exactly when this line is executed, the app crashes and closes.

I just solved this issue by following steps:

1.) organized me a MacBook Pro with Yosemite installed
2.) installed 5.1.1 version of Cordova (npm install -g cordova)
3.) created a new Cordova project
4.) added plugins and platform for iOS
5.) copied the www folder of old project to the www folder in the new project
6.) opened project in Xcode 6.4, added certificate, provision profile and all other resources like icons and splash images
7.) built the project and tested it on iOS 8.4 (iPad 4)

Now the camera plugin works like expected on iOS devices. I would have preferred a solution on the old environment (Xcode 5.1 and Cordova 4.2.0) but at last it works now.

Hope, I could help somebody to safe the day...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM