javascript - Phonegap打不开相机

标签 javascript ios cordova phonegap-plugins

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

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

这是在 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>

最佳答案

改变

destinationType: destinationType.FILE_URI

destinationType: destinationType.DATA_URL

在 getPhoto() 函数中。

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

Camera.DestinationType.DATA_URL

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

Phonegap Camera API Cannot read property data url of undefined

关于javascript - Phonegap打不开相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641375/

相关文章:

c# - 从网站解析实时源代码

javascript - 有没有办法在 <Route> 组件外部公开路由参数?

ios - Domain=kCFErrorDomainCFNetwork Code=303 这个错误代码是什么意思?

ios - iOS 7.0 中的 AVSpeechSynthesizer 有美国男声吗?

android - 构建 Cordovo Android 应用程序失败 - Dex 无法解析版本 52 字节代码错误消息

javascript - PhoneGap 构建服务 "Build in HTML5, CSS, JavaScript"声明

javascript - 饼图而不是谷歌地图中的标记簇图标

javascript - Golang/ReactJS CORS 问题

ios - 尝试将带有参数的方法作为选择器传递时出错

ios - ionic 框架iOS输入焦点问题