diff options
author | geequlim <geequlim@gmail.com> | 2018-01-20 23:17:39 +0800 |
---|---|---|
committer | geequlim <geequlim@gmail.com> | 2018-02-01 23:29:39 +0800 |
commit | 5980bef67294e861b25071df76c0169e360a2f76 (patch) | |
tree | 4e183ac4a62622f11fb5ee544ac7df35148a1ce6 /platform/osx | |
parent | df1c16d0fe06426dfdea8259878e479b38623d04 (diff) |
OSX: implement OS.get_unique_id
Update the documentations for OS.get_unique_id()
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/os_osx.h | 2 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index d9ad0a7db8..41e0585af6 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -229,6 +229,8 @@ public: virtual void set_ime_position(const Point2 &p_pos); virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp); + virtual String get_unique_id() const; + virtual OS::PowerState get_power_state(); virtual int get_power_seconds_left(); virtual int get_power_percent_left(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index ab54f62045..56ba80031b 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -963,6 +963,30 @@ void OS_OSX::set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_ } } +String OS_OSX::get_unique_id() const { + + static String serial_number; + + if (serial_number.empty()) { + io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); + CFStringRef serialNumberAsCFString = NULL; + if (platformExpert) { + serialNumberAsCFString = (CFStringRef)IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0); + IOObjectRelease(platformExpert); + } + + NSString *serialNumberAsNSString = nil; + if (serialNumberAsCFString) { + serialNumberAsNSString = [NSString stringWithString:(NSString *)serialNumberAsCFString]; + CFRelease(serialNumberAsCFString); + } + + serial_number = [serialNumberAsNSString UTF8String]; + } + + return serial_number; +} + void OS_OSX::set_ime_position(const Point2 &p_pos) { im_position = p_pos; } |