繁体   English   中英

相机插件使Cordova应用在iOS上崩溃,但在Android上却没有

[英]Camera plugin crashes Cordova app on iOS but not on Android

我在Cordova 4.2.0上为Android和iOS开发了一个应用程序。 在为Android应用成功签名并在Galaxy Note 10.1上测试了所有功能之后,我将www代码复制到了MacBook上,并为iPad 4(iOS 8.3)构建了该代码。

该应用程序可在两种设备上完美运行,但不能做到这一点:

1.)单击“相机”按钮可打开Android上的相机,我可以拍摄照片。 选择“使用”后,照片将上传到服务器,并且屏幕翻转回到概览,显示照片。

2.)在iOS上,单击“相机”按钮(应显示相机时)会导致整个应用程序崩溃。 因此,相机甚至没有打开。 在调试控制台上,我没有得到任何输出,因为调试器会立即失去与应用程序的连接。

可能是什么问题呢? 接下来,我将我的代码用于此功能:

//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); }
}

预先感谢您对可能出问题的任何想法...

编辑

调试过多的断点后,仅提供一些其他信息:

问题似乎在这一行:

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

而且我还尝试了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)});

恰好在执行此行时,应用程序崩溃并关闭。

我只是通过以下步骤解决了这个问题:

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)

现在,相机插件的工作方式与iOS设备上预期的一样。 我希望在旧环境(Xcode 5.1和Cordova 4.2.0)上有一个解决方案,但最后它现在可以工作了。

希望我能帮助某人安全过日子...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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