Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
摄像头插件在iOS上崩溃Cordova应用程序,但在Android上不会_Android_Ios_Cordova_Camera - Fatal编程技术网

摄像头插件在iOS上崩溃Cordova应用程序,但在Android上不会

摄像头插件在iOS上崩溃Cordova应用程序,但在Android上不会,android,ios,cordova,camera,Android,Ios,Cordova,Camera,我在Cordova4.2.0上为Android和iOS开发了一个应用程序。在成功签署Android应用程序并在Galaxy Note 10.1上测试所有功能后,我将www代码复制到我的MacBook上,并为我的iPad4(iOS 8.3)构建了它 该应用程序在这两种设备上都能完美运行,但有一点不行: 1.)Android上的摄像头在单击摄像头按钮时打开,我可以拍摄照片。选择“使用”后,照片将上载到服务器,屏幕翻转回概览,显示照片 2.)在iOS上,点击摄像头按钮(当摄像头出现时),整个应用程序都

我在Cordova4.2.0上为Android和iOS开发了一个应用程序。在成功签署Android应用程序并在Galaxy Note 10.1上测试所有功能后,我将www代码复制到我的MacBook上,并为我的iPad4(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)上有一个解决方案,但现在它终于可以工作了


希望,我能帮助某人安全度过这一天…

你已经这么做了吗?jslint.com向我展示了if和之间缺少的大量空格(但没有任何用处…此代码在Android上的工作方式与预期相同,但在iOS上却不一样。不知道jslint.com如何帮助我!?在Xcode中添加一个未捕获异常的常规断点,您应该会得到有关情况的提示。可能是info.plist未配置用于相机设备资源(众多功能中的一个)。感谢Yves的想法。1)我已经在iOS上使用了它,但后来我将应用分成了两个部分,都带有摄像头功能。但我没有更改getPhoto和sendImage功能中的任何内容。2。)我不能在Xcode中调试,因为我的SDK有点旧了,我不想因为安装新的SDK而冒任何风险。所以我通过iTunes连接在windows机器上调试GapDebug程序。工作完美,但是-如果应用程序崩溃,它无法显示任何原因…打开平台/ios xcode项目并从那里运行,您可能会得到更多信息这应该是个问题