我有一个按钮,onclick 类函数 getImage();当我在装有 ios 10 的 iphone 7 plus 上调用它时,它崩溃了。有人可以告诉我为什么会发生这种情况,并给我正确的代码来阻止这种情况。这是我现在拥有的代码,它曾经可以工作,并且仍然可以在旧版 ios 和 android 上工作。
navigator.camera.getPicture 函数在 iOS 10 设备上崩溃。
function getImage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function(message) {
alert('get picture failed');
}, {
quality: 80,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation : true,
allowEdit: true
}
);
}
function uploadPhoto(imageURI) {
//function sendPhoto(filetype){
var options = new FileUploadOptions();
options.fileKey="file";
//get file name
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
//Check if the device is android or not and if it is use the folowing code
var devicePlatform = device.platform;
if(devicePlatform == "Android"){
//check file extension
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1)+".jpeg";
}
var params = new Object();
params.value1 = "Babatunde";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "uploadUserPhoto.php", win, fail, options);
//Part of the commment out function sendPhoto
//}
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
最佳答案
您必须在 iOS 10 的 Info.plist 中添加此权限
Camera :
关键:隐私 - 相机使用说明
值:$(PRODUCT_NAME) 相机使用
Photo :
关键:隐私 - 照片库使用说明
值(value):$(PRODUCT_NAME)张照片使用
关于ios - PhoneGap 相机在 ios 10 上无法使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41177717/