Cordova Camera插件在iOS上崩溃

时间:2018-04-09 00:07:32

标签: javascript ios cordova cordova-plugins cordova-plugin-camera

我正在尝试在应用程序中使用Cordova相机插件。它在Android设备上运行良好,但由于某些原因在iOS设备上安装时会崩溃应用程序。在iOS模拟器中调用相机时,它会失败。(因为模拟器显然没有相机)。这个问题有什么解决方案吗?

HTML

<!--Save my look-->
<div id="saveMyLook">
<div id="cameraSection">
<button id="cameraBtn">Lets take a picture</button>
<img id="myImage" width="35%" height="35%" />
</div>
</div>

的Javascript

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(navigator.camera);
}
var camBtn=document.getElementById("cameraBtn");

function cam (){
    navigator.camera.getPicture(onSuccess, onFail,
    {sourceType: Camera.PictureSourceType.CAMERA});

function onSuccess(imageURI) {
    var image = document.getElementById('myImage');
    image.src = imageURI;
}

function onFail(message) {
    alert( message);
}
}
 camBtn.addEventListener('click',cam); 

的Config.xml

 <?xml version='1.0' encoding='utf-8'?>
 <widget id="com.MakeMePretty.joshua" version="1.0.0" 
 xmlns="http://www.w3.org/ns/widgets" 
 xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MakeMePretty</name>
<description>
    A sample Apache Cordova application that responds to the 
      deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="market:*" />
</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>
<plugin name="cordova-plugin-camera" spec="^4.0.2">
    <variable name="CAMERA_USAGE_DESCRIPTION" value="Access Camera" />
    <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Need to 
 access photolibrary" />
</plugin>
<engine name="ios" spec="^4.5.4" />
<engine name="android" spec="^7.0.0" />

1 个答案:

答案 0 :(得分:2)

请将以下行添加到您的Info.plist中作为源代码:

<key>NSCameraUsageDescription</key> <string>Camera usage description</string>

这是因为在iOS 10之后,您必须定义并提供您的应用在Info.plist中访问的所有系统隐私敏感数据的使用说明。

可以找到更详细的解释,作为对此问题的回复:NSCameraUsageDescription in iOS 10.0 runtime crash?