检查ios phonegap中的相机存在 [英] Check camera existence in ios phonegap

查看:107
本文介绍了检查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?

推荐答案

我需要这样做,所以我把它添加到一个插件,我做了各种任务。目前只有iOS版本。

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.h

#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
@interface TomPhonegapUtility : CDVPlugin
- (void) isCameraAvailable:(CDVInvokedUrlCommand*)command;
@end

TomPhonegapUtility.m

TomPhonegapUtility.m

#import "TomPhonegapUtility.h"
#import <Cordova/CDV.h>
@implementation TomPhonegapUtility
- (void) isCameraAvailable:(CDVInvokedUrlCommand*)command {
    CDVPluginResult *pluginResult = nil;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:1];
    } else {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:0];
    }
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end

TomPhonegapUtility.js

TomPhonegapUtility.js

function TomPhoneGapUtility () {
    this.isCameraAvailable = function(successCallback) {
        cordova.exec(successCallback, function(){}, "TomPhonegapUtility", "isCameraAvailable", []);
    }
}

如何使用

var util = new TomPhoneGapUtility();
util.isCameraAvailable(function(hasCamera) {
    if (hasCamera) alert("YES");
    else alert("NO");
});

这篇关于检查ios phonegap中的相机存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆