在iOS上拍照后,Phonegap App崩溃了

时间:2014-02-24 05:46:54

标签: ios cordova ios7 camera

phonegap 3.3.0 iOS7

拍摄照片并按“使用此照片”按钮后,屏幕变黑,应用程序崩溃。 已将图像质量低于50%以避免内存问题。 但这仍然不适用:(

有人可以帮忙吗?

function onDeviceReady() {

    var pictureSource = navigator.camera.PictureSourceType;
    var destinationType = navigator.camera.DestinationType;


    function onPhotoDataSuccess(imageData) {
        var smallImage = document.getElementById('smallImage');
        smallImage.style.display = 'block';
        smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    var options = {
        quality: 40,
        destinationType: destinationType.FILE_URI
    };

    function capturePhoto() {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);
    }

    function onFail(message) {
        $('body').append(
        '<p>Failed because: ' + message + '</p>');
    }


    $('#capturePhoto').click(function(){
        capturePhoto();
    });

}

非常感谢!

3 个答案:

答案 0 :(得分:1)

尝试以下代码一次: -  另外,请检查一下您是否完成了config.xml中的Camera插件输入?

 <feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>
<feature name="Capture">
    <param name="ios-package" value="CDVCapture" />
 </feature>

And check below code in your html page :-

document.addEventListener("deviceready",onDeviceReady,false);


function onDeviceReady() {
                                            pictureSource=navigator.camera.PictureSourceType;
                                            destinationType=navigator.camera.DestinationType;
                        }
/*open camera for capture photo*/
function capturePhoto() {
             largeImage.src='';
                                 // Take picture using device camera and retrieve image as base64-encoded string
                                         navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 75,
                                                                     destinationType: destinationType.FILE_URI});

                               }

                              function onPhotoDataSuccess(imageURI) {
                                     // Uncomment to view the base64-encoded image data
                                     // Get image handle

                                           var largeImage = document.getElementById('largeImage');
                                         // Unhide image elements

                                             largeImage.style.display = 'block';
                                             // Show the captured photo
                                                 largeImage.src = imageURI;

                              }

答案 1 :(得分:1)

将CDVCapture功能放入我的XML中了!

快速的其他问题...... 有什么区别

<gap:plugin name="org.apache.cordova.camera" />

<feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>

我读到你应该将图像质量设置在50%以下,以避免在某些设备上崩溃。你知道这仍然是一个问题吗?

非常感谢你!

答案 2 :(得分:0)

为了在PhoneGap Build项目中包含核心插件,您只需将gap:plugin标记添加到config.xml文件即可。