检查 ios PhoneGap 中相机是否存在
在我的 phonegap
应用程序中拍照时,我想在显示两种源类型之前检查相机是否存在。例如,iPad 1 没有相机,因此我不想显示从相机
和我的照片
中选择源类型的弹出窗口。 phonegap
中是否有某些内容告诉我该设备中是否存在相机?
I want to check camera existence before showing the two source types when taking a picture in my phonegap
application. For example, iPad 1 doesn't have an Camera, therefore I don't want to show the popup to select source type from Camera
and My Photos
. Is there something in phonegap
that tell me camera exists in this device or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
目前,似乎没有办法查询相机是否存在。
这并不理想,但对您来说可能是一个安全保障。如果设备没有摄像头,对 getPicture 的调用将落入失败处理程序,该处理程序返回一条消息。当相机不可用时,该消息是:“没有可用的相机”。因此,您可以处理该故障一次,然后将某些内容保留在用户设置中,以便您以后可以查询。就像我说的,并不理想。如果 API 可以报告此特定故障,那么它还应该提供一种检查是否存在的方法。
失败:函数(消息){
if (message == "没有可用的相机") {
// 将其保存在某处,以便下次我们不必依赖失败处理程序来告诉我们相机不存在
}
}
Currently, there doesn't appear to be a way to query camera existence.
This is not ideal, but it could be a fail safe for you. If the device doesn't have a camera, a call to getPicture will fall into the fail handler, which returns a message. When the camera isn't available, that message is: "no camera available". So you could handle that failure once, then persist something in user settings, which you could query going forward. Like I said, not ideal. If the API can report this specific failure, it should also provide a way to check existence.
fail: function (message) {
if (message == "no camera available") {
// save this somewhere so next time we don't have to rely on the fail handler to tell us the camera doesn't exist
}
}
我需要这样做,所以我将其添加到我制作的用于执行各种任务的插件中。目前只有 iOS 版本。
TomPhonegapUtility.h
TomPhonegapUtility.m
TomPhonegapUtility.js
如何使用
I needed to do just this, so I added it to a plug in that I made to do various tasks. Only iOS versions so far.
TomPhonegapUtility.h
TomPhonegapUtility.m
TomPhonegapUtility.js
How to use
您可以从 UIDevice 类获取设备型号字符串并检查
You can get the device model string from UIDevice class and check this
应该能够调用此代码来检查任何设备上是否存在相机。
Should be able to call this code to check for existence of a camera on any device.
当尝试使用 HTML5 方式拍照时,我做了类似的事情:
请记住,如果您在 IOS 模拟器上使用过此解决方案或前一个解决方案,它会给您一个可靠的答案,模拟器似乎会返回它有一个相机,但无法模拟拍照,并且会返回错误 20 ...
我对 if 语句不满意,如果有人知道如何以更合乎逻辑的方式编写它,请让我我知道,我的 JS 知识有限。
I have done something like this when trying to use the HTML5 way of taking a picture :
Keep in mind that if you have used this solution or the previous one on the IOS simulator, it will give you a reliable answer, the simulator seem to return that it has a camera but is not able to simulate the taking of a picture and will return an error 20 ...
I am not happy with the if statement, if anybody know how to write this in a more logical way, please let me know, my JS knowhow is limited.
我认为这很好地解释了这一点,如果您还没有找到答案: http://docs.phonegap.com/en/1.4.1/phonegap_camera_camera.md.html#Camera
I think this explains it well, if you haven't found the answer as of yet: http://docs.phonegap.com/en/1.4.1/phonegap_camera_camera.md.html#Camera