【问题标题】:Cordova Camera plugin crashes on iOSCordova Camera 插件在 iOS 上崩溃
【发布时间】:2018-09-18 07:48:15
【问题描述】:

我正在尝试在应用程序中使用 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); 

配置.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" />

【问题讨论】:

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


    【解决方案1】:

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

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

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

    更详细的解释可以在这个问题的回复中找到:NSCameraUsageDescription in iOS 10.0 runtime crash?

    【讨论】:

    • 将这些添加到 Info.plist 文件中,但它不起作用。但是进入 Xcode 并将新目标添加到项目中,它现在可以工作了。谢谢。
    • 我的 plist 文件中有所有使用说明,但 iOS 应用程序仍然崩溃。我有一个正在生产的应用程序,它之前一直运行良好。由于某些混乱的原因,它不再起作用了。我打开库选择一两个文件,关闭对话框,然后应用程序在后续请求中崩溃。导航离开,下拉刷新等。没有错误没有警告没有什么。我唯一拥有的是我的 iPhone 8 上的崩溃日志,它说主线程被阻止超过 5 秒,并且引发了 Watchdog Transgression。有任何想法吗?我已经为此苦苦挣扎了两个星期了T_T
    • @Nexus 是否在相机出现之前或之后崩溃,如果是这样,可能是文件权限
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    相关资源
    最近更新 更多