- Home /
UnityDeviceUniqueIdentifier() on iOS7
We can't deploy on iOS7 devices due the following issue:
extern "C" const char* UnityDeviceUniqueIdentifier()
{
QueryDeviceID();
return [_DeviceID UTF8String]; <-- EXC_BAD_ACCESS (code=1,...)
}
We already adapted the DeviceSettings.mm like mentioned in this post: 192113-Unity-4-2-Seeing-Crash-on-iOS-Device-when-using-SystemInfo-deviceUniqueIdentifier which solved the issue for < iOS7 devices:
#if UNITY_PRE_IOS7_TARGET
static void _InitDeviceIDPreIOS7()
{
static const int MD5_DIGEST_LENGTH = 16;
// macaddr: courtesy of FreeBSD hackers email list
int mib[6] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0 };
mib[5] = ::if_nametoindex("en0");
size_t len = 0;
::sysctl(mib, 6, NULL, &len, NULL, 0);
char* buf = (char*)::malloc(len);
::sysctl(mib, 6, buf, &len, NULL, 0);
sockaddr_dl* sdl = (sockaddr_dl*)((if_msghdr*)buf + 1);
unsigned char* mac = (unsigned char*)LLADDR(sdl);
char macaddr_str[18]={0};
::sprintf(macaddr_str, "%02X:%02X:%02X:%02X:%02X:%02X", *mac, *(mac+1), *(mac+2), *(mac+3), *(mac+4), *(mac+5));
::free(buf);
unsigned char hash_buf[MD5_DIGEST_LENGTH];
CC_MD5(macaddr_str, sizeof(macaddr_str)-1, hash_buf);
char uid_str[MD5_DIGEST_LENGTH*2 + 1] = {0};
for(int i = 0 ; i < MD5_DIGEST_LENGTH ; ++i)
::sprintf(uid_str + 2*i, "%02x", hash_buf[i]);
// FROM http://forum.unity3d.com/threads/192113-Unity-4-2-Seeing-Crash-on-iOS-Device-when-using-SystemInfo-deviceUniqueIdentifier
_DeviceID = [[NSString stringWithUTF8String:uid_str] retain];
}
#endif
But in this case (we try to build to iOS7) this function shouldn't be called at all. We should get the VendorID instead (which works correctly if target version is set properly ;) ).
static void QueryDeviceID()
{
if(_DeviceID == nil)
{
#if UNITY_PRE_IOS7_TARGET
if(!_ios70orNewer)
_InitDeviceIDPreIOS7();
#endif
// first check vendor id
if(_DeviceID == nil)
{
QueryVendorID();
_DeviceID = _VendorID;
}
// then ad id if smth went wrong
if(_DeviceID == nil)
{
QueryAdID();
_DeviceID = _ADID;
}
}
}
Unfortunetly while I breakpointing the execution I see the UUID beeing received by the VendorID but in the end I still get the error. I saw _DeviceID being filled in corretly with a hash like string (I assume that's the UUID) but then its gone again?
Please help :)
Further related post:
Your answer
Follow this Question
Related Questions
ios 7 and xcode5 2 Answers
iOS 7 .. Xcode5 .. now have error 0 Answers
Upgraded to unity 4.2. Now all existing particle effects are ignoring 'Color Over Time' 1 Answer
Unity3D 3.5.7 - iOS 7 1 Answer
Unity Exception with ios 7 device..? 1 Answer