PhoneGap相机无法在ios 10上运行

时间:2016-12-16 05:20:22

标签: ios cordova phonegap-plugins

我有一个onclick类的按钮,函数getImage();当我在iphone 7上用ios 10拨打电话时它会崩溃。有人可以告诉我为什么会发生这种情况并给我正确的代码来阻止它。这是我现在使用的代码,用于工作,stil适用于较旧的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);
    }

2 个答案:

答案 0 :(得分:2)

您必须在Info.plist for iOS 10中添加此权限

  

相机:

密钥:隐私 - 相机使用说明
价值:$(PRODUCT_NAME)相机使用

  

照片:

密钥:隐私 - 照片库使用说明
价值:$(PRODUCT_NAME)照片使用

答案 1 :(得分:0)

应用程序崩溃iOS10而不是之前版本的原因是因为您需要为相机和相册添加权限。您需要为info.plist

添加权限

照片:

Key       :  Privacy - Photo Library Usage Description    
Value   :  $(PRODUCT_NAME) photo use

相机:

Key       :  Privacy - Camera Usage Description   
Value   :  $(PRODUCT_NAME) camera use

有关您需要在info.plist中指定的密钥列表,请参阅此Apple's documentation