Reputation: 39
I have a button that onclick class the function getImage(); and it crashes when I call it on my iphone 7 plus that has ios 10. Can someone please tell me why this is happening and give me the right code for to stop this. Here is the code I have as of now that used to work and stil works on older ios and android.
navigator.camera.getPicture function crashes on ios 10 device.
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);
}
Upvotes: 2
Views: 965
Reputation: 2419
Reason why app crashes on iOS10
and not on versions earlier is because you need to add permissions for Camera and Album. You need to add permissions to your info.plist
Photo :
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
Camera :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use
For list of keys you need to specify in your info.plist is in this Apple's documentation
Upvotes: 0
Reputation: 187
You have to add this permission in Info.plist for iOS 10
Camera :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use
Photo :
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
Upvotes: 2