我在iphone平台的cordova 2.9.0上运行了一个jqm + phonegap应用程序。 我确信我在xcode上有正确的cordova文件。
在Android上,我的代码工作得很好,但是在ios上,我的上传图片代码不起作用
JS:
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
// Do cool things here...
}
function getImage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto, function(message) {
alert('Get Picture Failed. Please Try Again.');
},{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=curClub+imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
params.clubID = curClub ;
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "url", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);;
}
function fail(error) {
alert("An error has occurred: Code = " = error.code);
}
HTML:
<div data-role = "button" onClick = "getImage();" >Upload Logo</div>
如果我通过在里面添加一个警告测试getImage()函数,它可以工作,所以我知道它会去那里。还有什么我做错了?
答案 0 :(得分:1)
请在OnDeviceReady方法中提及pictureSource和destinationType ..
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType; destinationType = navigator.camera.DestinationType; }