2016-12-16 67 views
2

我有一个onclick类的按钮getImage();它会崩溃,当我在我的iphone 7上加上它具有ios 10时调用它。有人可以告诉我为什么发生这种情况,并给我正确的代码来阻止它。这是我现在使用的代码,在老的ios和android上工作和stil。PhoneGap相机不能在ios 10上工作

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); 
    } 
+0

您是否在'info.plist'文件中添加了相机访问权限?请参阅此答案:http://stackoverflow.com/a/38498347/6449750 –

回答

2

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

摄像头:

重点:隐私 - 相机用法说明
价值:$(PRODUCT_NAME)相机使用

照片:

重点:隐私 - 图片库使用情况说明
价值:$(PRODUCT_NAME)的照片使用

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