You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2016/01/04 23:16:06 UTC
[2/2] cordova-plugin-device git commit: CB-10238 Move device-plugin
out from cordovalib to the plugin repository
CB-10238 Move device-plugin out from cordovalib to the plugin repository
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/commit/64956bb6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/tree/64956bb6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/diff/64956bb6
Branch: refs/heads/master
Commit: 64956bb66097bc187a0bade49329630b440ed647
Parents: dfc8211
Author: Tobias Bocanegra <tr...@adobe.com>
Authored: Mon Dec 21 16:30:39 2015 -0800
Committer: Tobias Bocanegra <tr...@adobe.com>
Committed: Mon Dec 21 16:30:39 2015 -0800
----------------------------------------------------------------------
src/osx/CDVDevice.h | 6 +--
src/osx/CDVDevice.m | 97 ++++++++++++++++++++++++++----------------------
2 files changed, 54 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/64956bb6/src/osx/CDVDevice.h
----------------------------------------------------------------------
diff --git a/src/osx/CDVDevice.h b/src/osx/CDVDevice.h
index a146d88..9def254 100644
--- a/src/osx/CDVDevice.h
+++ b/src/osx/CDVDevice.h
@@ -17,14 +17,12 @@
under the License.
*/
-#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
@interface CDVDevice : CDVPlugin
-{}
-+ (NSString*)cordovaVersion;
++ (NSString*) cordovaVersion;
-- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command;
+- (void) getDeviceInfo:(CDVInvokedUrlCommand*)command;
@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/64956bb6/src/osx/CDVDevice.m
----------------------------------------------------------------------
diff --git a/src/osx/CDVDevice.m b/src/osx/CDVDevice.m
index f58c321..3a63588 100644
--- a/src/osx/CDVDevice.m
+++ b/src/osx/CDVDevice.m
@@ -17,90 +17,97 @@
under the License.
*/
-#include <sys/types.h>
#include <sys/sysctl.h>
-#include "TargetConditionals.h"
-#import <Cordova/CDV.h>
#import "CDVDevice.h"
-@implementation UIDevice (ModelVersion)
+#define SYSTEM_VERSION_PLIST @"/System/Library/CoreServices/SystemVersion.plist"
-- (NSString*)modelVersion
-{
+@implementation CDVDevice
+
+- (NSString*) modelVersion {
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];
+ NSString* modelVersion = [NSString stringWithUTF8String:machine];
free(machine);
- return platform;
+ return modelVersion;
}
-@end
-
-@interface CDVDevice () {}
-@end
-@implementation CDVDevice
+- (NSString*) getSerialNr {
+ NSString* serialNr;
+ io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
+ if (platformExpert) {
+ CFTypeRef serialNumberAsCFString =
+ IORegistryEntryCreateCFProperty(platformExpert,
+ CFSTR(kIOPlatformSerialNumberKey),
+ kCFAllocatorDefault, 0);
+ if (serialNumberAsCFString) {
+ serialNr = (__bridge NSString*) serialNumberAsCFString;
+ }
+ IOObjectRelease(platformExpert);
+ }
+ return serialNr;
+}
-- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
-{
+- (NSString*) uniqueAppInstanceIdentifier {
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
static NSString* UUID_KEY = @"CDVUUID";
-
- // Check user defaults first to maintain backwards compaitibility with previous versions
- // which didn't user identifierForVendor
+
NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
+
if (app_uuid == nil) {
- app_uuid = [[device identifierForVendor] UUIDString];
+ CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
+ CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
+
+ app_uuid = [NSString stringWithString:(__bridge NSString*) uuidString];
[userDefaults setObject:app_uuid forKey:UUID_KEY];
[userDefaults synchronize];
+
+ CFRelease(uuidString);
+ CFRelease(uuidRef);
}
-
+
return app_uuid;
}
-- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
-{
+- (NSString*) platform {
+ return [NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST][@"ProductName"];
+}
+
+- (NSString*) systemVersion {
+ return [NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST][@"ProductVersion"];
+}
+
+- (void) getDeviceInfo:(CDVInvokedUrlCommand*) command {
NSDictionary* deviceProperties = [self deviceProperties];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-- (NSDictionary*)deviceProperties
-{
- UIDevice* device = [UIDevice currentDevice];
+- (NSDictionary*) deviceProperties {
NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
- [devProps setObject:@"Apple" forKey:@"manufacturer"];
- [devProps setObject:[device modelVersion] forKey:@"model"];
- [devProps setObject:@"iOS" forKey:@"platform"];
- [devProps setObject:[device systemVersion] forKey:@"version"];
- [devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"];
- [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
- [devProps setObject:@([self isVirtual]) forKey:@"isVirtual"];
+ devProps[@"manufacturer"] = @"Apple";
+ devProps[@"model"] = [self modelVersion];
+ devProps[@"platform"] = [self platform];
+ devProps[@"version"] = [self systemVersion];
+ devProps[@"uuid"] = [self uniqueAppInstanceIdentifier];
+ devProps[@"cordova"] = [[self class] cordovaVersion];
+ devProps[@"serial"] = [self getSerialNr];
+ devProps[@"isVirtual"] = @NO;
+
NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
return devReturn;
}
-+ (NSString*)cordovaVersion
-{
++ (NSString*) cordovaVersion {
return CDV_VERSION;
}
-- (BOOL)isVirtual
-{
- #if TARGET_OS_SIMULATOR
- return true;
- #elif TARGET_IPHONE_SIMULATOR
- return true;
- #else
- return false;
- #endif
-}
-
@end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org