Phonegap不会打开相机

时间:2014-02-08 03:01:51

标签: javascript ios cordova phonegap-plugins

好吧我试图让照片库打开,然后从那里我将开始将其上传到服务器。但目前相机库无法打开。我从文档中复制了这个例子。然后我在config.xml中添加了设备以及运行cordova plugin add命令。

但是当我运行应用程序并单击按钮时没有任何反应。我是新的cordova插件而不是javascript的向导。我也在v3.3 for iOS。

这是在config.xml

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

这是photo.html

<html>
<head>
    <title>Capture Photo</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

        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() {
            pictureSource=navigator.Camera.PictureSourceType;
            destinationType=navigator.Camera.DestinationType;
        }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageData) {

        var smallImage = document.getElementById('smallImage');


        smallImage.style.display = 'block';

        // Show the captured photo
        // The in-line CSS rules are used to resize the image
        //
        smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
        // Uncomment to view the image file URI
        // console.log(imageURI);

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

        // Unhide image elements
        //
        largeImage.style.display = 'block';

        // Show the captured photo
        // The in-line CSS rules are used to resize the image
        //
        largeImage.src = imageURI;
    }

    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) {
        alert('Failed because: ' + message);
    }

        </script>
</head>
<body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
</body>

1 个答案:

答案 0 :(得分:0)

更改

destinationType: destinationType.FILE_URI

destinationType: destinationType.DATA_URL

在你的getPhoto()函数中。

如果这不起作用,请尝试:

Camera.DestinationType.DATA_URL

另请查看此网址以获取更多答案:

Phonegap Camera API Cannot read property data url of undefined

相关问题