【发布时间】:2013-09-16 23:33:07
【问题描述】:
我有一个 jqm+phonegap 应用程序在适用于 ios 平台的 cordova 2.9.0 上运行。 我确信我在 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() 函数,它可以工作,所以我知道它会去那里。我还有什么做错的?
【问题讨论】: