Hello All,
I’m looking to recreate (or duplicate) SystemInfo.deviceUniqueIdentifier in the same manner that Unity creates them. This is purely so that they match between our code bases. They come from the SystemInfo.deviceUniqueIdentifier api in C#.
I’d like to recreate them in c++ or native on the following platforms:
Android (done)
Windows exe
Windows Browser
Mac OS X app (done)
Mac Browser (done)
iOS (done)
Android (may not be correct on all devices):
if( g_strSecureAndroidId == null ){
g_strSecureAndroidId = Settings.Secure.getString(MainActivity.sInstance.getContentResolver(), Settings.Secure.ANDROID_ID);
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(g_strSecureAndroidId.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] 0xFF) | 0x100).substring(1,3));
}
g_strSecureAndroidId = sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
// do nothing if no such algorithm
}
}
return g_strSecureAndroidId;
Mac Implementation:
CFUUIDBytes uuidBytes;
const struct timespec spec = {0, 0};
gethostuuid((unsigned char *)&uuidBytes, &spec);
CFUUIDRef uuid = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, uuidBytes);
CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuid);
NSString * uuidNSString = (NSString* ) uuidString;
if (uuid) CFRelease(uuid);
std::string temp = std::string([uuidNSString UTF8String]);
return temp;
For windows, it looks like sha1 but of what? Also it uses the same number that the browsers builds use.
Now for iOS, you can look at the stickie on the forums for this one. Easiest method is to build for iOS and copy unity methods into your objective-c.