Browse Source

OSX: implement OS.get_unique_id
Update the documentations for OS.get_unique_id()

geequlim 7 năm trước cách đây
mục cha
commit
5980bef672
3 tập tin đã thay đổi với 28 bổ sung1 xóa
  1. 2 1
      doc/classes/OS.xml
  2. 2 0
      platform/osx/os_osx.h
  3. 24 0
      platform/osx/os_osx.mm

+ 2 - 1
doc/classes/OS.xml

@@ -346,7 +346,8 @@
 			<return type="String">
 			</return>
 			<description>
-				Returns a string that is unique to the device. Currently only works on Android and iOS. Returns empty string on other platforms.
+				Returns a string that is unique to the device.
+				Returns empty string on HTML5 and UWP which are not supported yet.
 			</description>
 		</method>
 		<method name="get_unix_time" qualifiers="const">

+ 2 - 0
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();

+ 24 - 0
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;
 }