Created
December 21, 2012 10:37
-
-
Save oiledCode/4352031 to your computer and use it in GitHub Desktop.
EDDeviceHardwarePlugin ( a cordova plugin to get info about the device )
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
#import <Cordova/CDVPlugin.h> | |
@interface EDDeviceHardwarePlugin : CDVPlugin | |
-(void)getPlatform:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; | |
-(void)getPlatformString(NSMutableArray*)arguments withDict:(NSMutableDictionary*)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
#import "EDDeviceHardwarePlugin.h" | |
#include <sys/types.h> | |
#include <sys/sysctl.h> | |
@implementation EDDeviceHardwarePlugin | |
-(void)getPlatform:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{ | |
NSString *callBackID = arguments[0]; | |
size_t size; | |
sysctlbyname("hw.machine", NULL, &size, NULL, 0); | |
char *machine = malloc(size); | |
sysctlbyname("hw.machine", machine, &size, NULL, 0); | |
NSString *platform = [NSString stringWithUTF8String:machine]; | |
free(machine); | |
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:platform]; | |
NSString *jScript = [pluginResult toSuccessCallbackString:self.callBackId]; | |
[self writeJavascript:jScript]; | |
} | |
-(void)getPlatformString(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{ | |
NSString *callBackID = arguments[0]; | |
NSString *platform = [self platform]; | |
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G"; | |
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; | |
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS"; | |
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4"; | |
if ([platform isEqualToString:@"iPhone3,3"]) return @"Verizon iPhone 4"; | |
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; | |
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G"; | |
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G"; | |
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G"; | |
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G"; | |
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad"; | |
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)"; | |
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)"; | |
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)"; | |
if ([platform isEqualToString:@"i386"]) return @"Simulator"; | |
if ([platform isEqualToString:@"x86_64"]) return @"Simulator"; | |
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:platform]; | |
NSString *jScript = [pluginResult toSuccessCallbackString:self.callBackId]; | |
[self writeJavascript:jScript]; | |
} | |
@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
var EDDeviceHardwarePlugin. = { | |
getPlatform : function(params,callBack){ | |
return cordova.exec(callBack,function(err){ | |
ddd('plugin error'); | |
}, | |
'EDDeviceHardwarePlugin.', 'getPlatform',[params] | |
); | |
}, | |
getPlatformString : function(params,callBack){ | |
return cordova.exec(callBack,function(err){ | |
ddd('plugin error'); | |
}, | |
'EDDeviceHardwarePlugin.', 'getPlatformString',[params] | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment