Skip to content

Instantly share code, notes, and snippets.

@lukasklein
Created June 12, 2015 12:25
Show Gist options
  • Save lukasklein/f99d5e80a2880765a283 to your computer and use it in GitHub Desktop.
Save lukasklein/f99d5e80a2880765a283 to your computer and use it in GitHub Desktop.
//
// CameraAvailable.h
//
//
// Created by Lukas Klein on 08-19-11.
// MIT Licensed
// Copyright (c) Lukas Klein
#import <foundation foundation.h="">
#ifdef PHONEGAP_FRAMEWORK
#import <phonegap pgplugin.h="">
#else
#import "PGPlugin.h"
#endif
@interface CameraAvailable : PGPlugin { }
- (void)hasCamera:(NSArray*)arguments withDict:(NSDictionary*)options;
@end
//
// CameraAvailable.js
//
//
// Created by Lukas Klein on 08-19-11.
// MIT Licensed
// Copyright (c) Lukas Klein
function CameraAvailable() {};
CameraAvailable.prototype.hasCamera = function(result)
{
return PhoneGap.exec("CameraAvailable.hasCamera", GetFunctionName(result));
}
PhoneGap.addConstructor(function()
{
if(!window.plugins)
{
window.plugins = {};
}
window.plugins.CameraAvailable = new CameraAvailable();
});
//
// CameraAvailable.m
//
//
// Created by Lukas Klein on 08-19-11.
// MIT Licensed
// Copyright (c) 2011 Lukas Klein
#import "CameraAvailable.h"
@interface CameraAvailable (Private)
-(void) callbackWithFuntion:(NSString *)function withData:(NSString *)value;
@end
@implementation CameraAvailable
- (void)hasCamera:(NSArray*)arguments withDict:(NSDictionary*)options
{
NSUInteger argc = [arguments count];
if (argc < 1) {
return;
}
bool hascamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
NSString *callBackFunction = [arguments objectAtIndex:0];
[self callbackWithFuntion:callBackFunction withData:[NSString stringWithFormat:@"{available: %@}", (hascamera ? @"true" : @"false")]];
}
-(void) callbackWithFuntion:(NSString *)function withData:(NSString *)value{
if (!function || [@"" isEqualToString:function]){
return;
}
NSString* jsCallBack = [NSString stringWithFormat:@"%@(%@);", function, value];
[self writeJavascript: jsCallBack];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment