2014-02-08 78 views
1

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

但是,当我运行该应用程序,然后单击按钮什么都不会发生。我是新来的科尔多瓦插件,而不是JavaScript上的向导。我也在iOS v3.3上。

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

+0

WATS德错误? –

+0

@DiveshSalian当我点击按钮打开相机库时,没有错误代码编译并运行模拟器。 – sdla4ever

+0

您是否从命令行添加了所需的插件?如果您在Chrome中启动HTML并使用控制台进行调试,它通常会告诉您缺少什么 – terrorfall

回答