javascript 无法在 iOS phonegap adobe build 上使用 navigator.camera.getPicture

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20924734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:37:23  来源:igfitidea点击:

Can't use navigator.camera.getPicture on iOS phonegap adobe build

javascripthtmlcordovaphonegap-build

提问by user1044220

I have been looking for hours now and can't get my phonegap app (compiled by adobe phonegap build) and I fear I am missing something about phonegap. I have added the following lines to the config.xml file:

我一直在寻找几个小时,但无法获得我的 phonegap 应用程序(由 adobe phonegap build 编译),我担心我错过了有关 phonegap 的一些信息。我在 config.xml 文件中添加了以下几行:

<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/camera"/>

I try to take the picture using the following code:

我尝试使用以下代码拍照:

navigator.camera.getPicture(function(image) {callback("data:image/jpeg;base64," + image)}, cameraFail, { quality: 49 }); 

I am testing it by running it on an iPad2 running iOS 7. I've created a rudimentary inapp console and the problem appears to be that navigator.camera does not exist. Thanks for reading hope you can help.

我正在通过在运行 iOS 7 的 iPad2 上运行它来测试它。我创建了一个基本的 inapp 控制台,问题似乎是 navigator.camera 不存在。感谢阅读希望对你有所帮助。

回答by user1044220

With help from another answer it lead me to realize what I had done wrong so i'll post for anyone else that is in the same boat.

在另一个答案的帮助下,它让我意识到我做错了什么,所以我会为同一条船上的其他人发帖。

I hadn't included a reference to cordova.js which should be done just by adding a normal script tag like this:

我没有包含对cordova.js的引用,这应该通过添加一个像这样的普通脚本标签来完成:

<script src="cordova.js"></script>

I hadn't included it as I did not have the file cordova.js. What I did not realize is when using the adobe Phonegap Build service the file is added automatically and I did not need it in my source directory, just to include the tag.

我没有包含它,因为我没有文件cordova.js。我没有意识到的是,当使用 adobe Phonegap Build 服务时,文件会自动添加,我的源目录中不需要它,只是为了包含标签。

回答by vonBerg

Installing plugins for PhoneGap can be difficult.

为 PhoneGap 安装插件可能很困难。

Do you have the following functions in your code?

您的代码中有以下功能吗?

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
? ? destinationType: Camera.DestinationType.DATA_URL
?}); 

function onSuccess(imageData) {
? ? var image = document.getElementById('myImage');
? ? image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
? ? alert('Failed because: ' + message);
}

Your config.xml seems ok.

你的 config.xml 看起来没问题。

Also, check the following links:

另外,请检查以下链接:

https://build.phonegap.com/plugins/242

https://build.phonegap.com/plugins/242

https://github.com/apache/cordova-plugin-camera/tree/fed4f2280d786cabb24641eb6ce686acf98d0a94(Contains test folder so you can test it on your device)

https://github.com/apache/cordova-plugin-camera/tree/fed4f2280d786cabb24641eb6ce686acf98d0a94(包含测试文件夹,因此您可以在您的设备上对其进行测试)