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>
WATS德錯誤? –
@DiveshSalian當我點擊按鈕打開相機庫時,沒有錯誤代碼編譯並運行模擬器。 – sdla4ever
您是否從命令行添加了所需的插件?如果您在Chrome中啓動HTML並使用控制檯進行調試,它通常會告訴您缺少什麼 – terrorfall