gpt4 book ai didi

javascript - Cordova Camera 插件在 iOS 上崩溃

转载 作者:行者123 更新时间:2023-11-30 14:40:41 27 4
gpt4 key购买 nike

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

最佳答案

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

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

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

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

关于javascript - Cordova Camera 插件在 iOS 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49724017/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com