Phonegap无法在iPad视网膜迷你iOS7中使用相机

时间:2014-05-12 10:32:58

标签: ios ipad cordova camera

我在iPad上构建了一个应用程序。它适用于2台iPad 2(iOS 6.1和iOS 7.1) 但是,然后我在iPad视网膜迷你iOS 7(型号:ME820ZP / A)上测试,当我选择照片或拍照时它就崩溃了。

这是我的手机缺口代码:`

var pictureSource;   // picture source
var destinationType; // sets the format of returned value

// Wait for device API libraries to load
//
document.addEventListener("deviceready",onDeviceReady,false);

// device APIs are available
//
function onDeviceReady() {

    // init for photo
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;


}


// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI) {

  // Get image handle
  var imgAvatar = document.getElementById('avatar');

  // Unhide image elements
  imgAvatar.style.display = 'block';
  // add into img element
  imgAvatar.src = imageURI;

 // local storage
  window.localStorage.setItem('User_Avatar',imageURI);
}

// A button will call this function
function capturePhotoEdit() {
  // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, allowEdit: true,
    destinationType: destinationType.FILE_URI });
}

// A button will call this function
function getPhoto(source) {
  // Retrieve image file location from specified source
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI,
    sourceType: source });
}

// Called if something bad happens.
function onFail(message) {
    showAlert("Có lỗi: " + message);
}

// alert dialog dismissed
function alertDismissed() {
    // do something
}
// Show a custom alert
//
function showAlert(message) {
    navigator.notification.alert(
        message,  // message
        alertDismissed,         // callback
        'Thông báo',            // title
        'OK'                  // buttonName
    );
}

` 当然,插件org.apache.cordova.camera已添加。

这是调试屏幕:http://thienhaxanh.info/debug-screen.png(抱歉,我无法发布图片:))

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试内联功能....我认为大部分时间似乎都在工作......

function takeasnap() {
    try {
        navigator.camera.getPicture(

            function (uri) {
                alert(uri);
            },
            function (e) {
                console.log("Error getting picture: " + e);
            }, {
                quality: 50
            }
        );
    } catch (err) {
        alert(err);
    }
}