【问题标题】:PhoneGap camera is not working on ios 10PhoneGap 相机无法在 ios 10 上运行
【发布时间】:2017-05-01 20:32:45
【问题描述】:

我有一个 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 cordova phonegap-plugins


【解决方案1】:

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

相机:

关键:隐私 - 相机使用说明
价值:$(PRODUCT_NAME) 相机使用量

照片:

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

【讨论】:

    【解决方案2】:

    应用在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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多