Phonegap应用程序在iOS上拍照后崩溃

Phonegap应用程序在iOS上拍照后崩溃,ios,cordova,ios7,camera,Ios,Cordova,Ios7,Camera,phonegap 3.3.0 损失7 拍照并按下“使用此照片”按钮后,屏幕变黑,应用程序崩溃。 已将图像质量降低到50%以下,以避免内存问题。 但这仍然不起作用:( 有人能帮忙吗 function onDeviceReady() { var pictureSource = navigator.camera.PictureSourceType; var destinationType = navigator.camera.DestinationType; functi

phonegap 3.3.0 损失7

拍照并按下“使用此照片”按钮后,屏幕变黑,应用程序崩溃。 已将图像质量降低到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();
    });

}
函数ondevicerady(){
var pictureSource=navigator.camera.PictureSourceType;
var destinationType=navigator.camera.destinationType;
函数onPhotoDataSuccess(imageData){
var smallImage=document.getElementById('smallImage');
smallImage.style.display='block';
smallImage.src=“数据:图像/jpeg;base64,”+imageData;
}
变量选项={
质量:40,
destinationType:destinationType.FILE\u URI
};
函数capturePhoto(){
navigator.camera.getPicture(onPhotoDataSuccess、onFail、options);
}
函数onFail(消息){
$('body')。追加(
“失败,因为:“+message+”

”; } $(“#capturePhoto”)。单击(函数(){ capturePhoto(); }); }
非常感谢!

请尝试以下代码一次:- 另外,请检查一下您是否在config.xml中输入了摄像头插件

 <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;

                              }

并检查html页面中的以下代码:-
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
函数ondevicerady(){
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.destinationType;
}
/*打开相机拍摄照片*/
函数capturePhoto(){
largeImagesrc='';
//使用设备摄像头拍照,并将图像作为base64编码字符串检索
navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:75,
destinationType:destinationType.FILE_URI});
}
函数onPhotoDataSuccess(imageURI){
//取消注释以查看base64编码的图像数据
//获取图像句柄
var largeImage=document.getElementById('largeImage');
//取消隐藏图像元素
largeImage.style.display='block';
//显示捕获的照片
largeImage.src=imageURI;
}

将CDVCapture功能放入我的XML中就成功了

快速回答其他问题。。。 两者的区别是什么

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


?

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


非常感谢!

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

太好了!非常有效。完全没有意识到将CDVCapture功能放入我的xml文件中!如果您使用CLI,则不需要该功能。发件人:如果使用CLI生成应用程序,则使用plugin命令启用设备API。这不会修改顶级config.xml文件,因此该元素不适用于您的工作流
<feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>