ios - PhoneGap 相机在 ios 10 上无法使用

标签 ios cordova phonegap-plugins

我有一个按钮,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/

相关文章:

iphone - 取消时删除 UITableView 单元格的 UIActionSheet 一直显示按下的删除按钮

ios - 带有 xcode 5.1 的 cordova 3.4 不会使用最新的文件传输插件构建

objective-c - PhoneGap/Cordova iOS : capture video with a duration limit (ie. 30 秒)

ios - 在 iPad 上使用 Touch ID 登录多用户应用程序

iphone - ios 的 Cordova 3.0.0 ActionSheet 插件无法正常工作

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : 'Unable to serialize CPDistributedMessagingCenter

ios - 选项卡栏,当来自另一个选项卡的 View Controller 时弹出到 Root View Controller (默认 vc)

IOS调用另一个类的方法

ios - 缺少 APNs 证书。在设置中上传证书

ios - 如何在存折卡背面列出我的应用程序?