Created
June 12, 2015 12:25
-
-
Save lukasklein/f99d5e80a2880765a283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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