You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/03/07 07:23:12 UTC
mac commit: Implemented CDVDevice core plugin.
Updated Branches:
refs/heads/master 7b2fb3de2 -> 542771bde
Implemented CDVDevice core plugin.
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/542771bd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/542771bd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/542771bd
Branch: refs/heads/master
Commit: 542771bde7adea936d8eaac7ddf519d6387bdedc
Parents: 7b2fb3d
Author: Shazron Abdullah <sh...@apache.org>
Authored: Wed Mar 6 22:23:04 2013 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Mar 6 22:23:04 2013 -0800
----------------------------------------------------------------------
CordovaMac/CordovaLib/Commands/CDVDevice.m | 47 ++++++++++++++++++----
1 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/542771bd/CordovaMac/CordovaLib/Commands/CDVDevice.m
----------------------------------------------------------------------
diff --git a/CordovaMac/CordovaLib/Commands/CDVDevice.m b/CordovaMac/CordovaLib/Commands/CDVDevice.m
index 9728301..2338374 100644
--- a/CordovaMac/CordovaLib/Commands/CDVDevice.m
+++ b/CordovaMac/CordovaLib/Commands/CDVDevice.m
@@ -23,6 +23,8 @@
#import "CDVDevice.h"
#import "CDVAvailability.h"
+#define SYSTEM_VERSION_PLIST @"/System/Library/CoreServices/SystemVersion.plist"
+
@implementation CDVDevice
- (NSString*)modelVersion
@@ -32,28 +34,55 @@
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;
}
- (NSString*)model
{
- // TODO:
- return @"";
+ size_t size;
+
+ sysctlbyname("hw.model", NULL, &size, NULL, 0);
+ char* model = malloc(size);
+ sysctlbyname("hw.model", model, &size, NULL, 0);
+ NSString* name = [NSString stringWithUTF8String:model];
+ free(model);
+
+ return name;
}
- (NSString*)uniqueAppInstanceIdentifier
{
- // TODO:
- return @"";
+ NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
+ static NSString* UUID_KEY = @"CDVUUID";
+
+ NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
+
+ if (app_uuid == nil) {
+ 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;
+}
+
+- (NSString*) platform
+{
+ return [[NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST] objectForKey:@"ProductName"];
}
- (NSString*)systemVersion
{
- // TODO:
- return @"";
+ return [[NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST] objectForKey:@"ProductVersion"];
}
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
@@ -69,7 +98,7 @@
NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
[devProps setObject:[self modelVersion] forKey:@"model"];
- [devProps setObject:@"OS X" forKey:@"platform"];
+ [devProps setObject:[self platform] forKey:@"platform"];
[devProps setObject:[self systemVersion] forKey:@"version"];
[devProps setObject:[self uniqueAppInstanceIdentifier] forKey:@"uuid"];
[devProps setObject:[self model] forKey:@"name"];