【问题标题】:Phonegap won't open cameraPhonegap 打不开相机
【发布时间】:2014-02-08 03:01:50
【问题描述】:

好吧,我正在尝试打开照片库,然后从那里开始将其上传到服务器。但目前相机库不会打开。我已经从文档中复制了示例。然后我在 config.xml 中添加了设备,同时运行了 cordova plugin add 命令。

但是当我运行应用程序并单击按钮时,什么也没有发生。我是 cordova 插件的新手,而不是 javascript 向导。我也在使用 v3.3 for iOS。

这是在 config.xml 中

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

这是照片.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>

【问题讨论】:

  • @DiveshSalian 当我单击按钮打开相机库时,它编译并运行模拟器没有错误代码,没有任何反应。
  • 您是否从命令行添加了所需的插件?如果您在 Chrome 中启动 HTML,并使用控制台进行调试,它通常会告诉您缺少什么

标签: javascript ios cordova phonegap-plugins


【解决方案1】:

改变

destinationType: destinationType.FILE_URI

destinationType: destinationType.DATA_URL

在您的 getPhoto() 函数中。

如果这不起作用,试试这个:

Camera.DestinationType.DATA_URL

还可以查看此 URL 以获得更多答案:

Phonegap Camera API Cannot read property data url of undefined

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多