Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by luape · Jul 31, 2013 at 11:45 PM · iosunity 4.2

deviceUniqueIdentifier for iOS changed since upgrading to 4.2

We upgraded our project to Unity 4.2 recently and noticed SystemInfo.deviceUniqueIdentifier is returning differently to older Unity versions in iOS devices.

Is this expected? Anything we can do to keep using the device id of old version?

Many thanks, Lu

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by luape · Aug 01, 2013 at 11:46 PM

Not sure if it is breaking the rule to answer my own question. But here goes:

Turns out the md5 function used in Unity 4.2 is not the same as previous versions. To keep old deviceUniqueIdentifier here are the changes:

In XCode project generated by Unity, find file called DeviceSettings.mm, inside _InitDeviceIDPreIOS7()

REPLACE:

         unsigned char hash_buf[MD5_DIGEST_LENGTH];
         CC_MD5(macaddr_str, sizeof(macaddr_str), 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]);
 
         _DeviceID = [NSString stringWithUTF8String:uid_str];

WITH:

     unsigned char result[16];
     CC_MD5( macaddr_str, strlen(macaddr_str), result );
     _DeviceID =  [[NSString stringWithFormat:
                   @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
                   result[0], result[1], result[2], result[3],
                   result[4], result[5], result[6], result[7],
                   result[8], result[9], result[10], result[11],
                   result[12], result[13], result[14], result[15]
                   ] retain];

Used retain or it will crash on later deviceUniqueIdentifier calls, which is another bug in Unity4.2. (md5 code from another stackoverflow post)

The problem with this change is that you will have to change on every developer machine as the code is part of Unity's application. For this reason, we made our own iOS plugin, which returns the same result. And we start calling that plugin instead of SystemInfo.deviceUniqueIdentifier. This way, the code is bound to our project and carries across to all developers checking out the repository.

You should also know that from iOS7, there is a possibility that MAC address may be blocked. When this happens, there is no way for current unique device id to work. You should plan for migration methods to (post ios7) deviceUniqueIdentifier method using ios vender id, etc.

Hope this helps.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Aug 01, 2013 at 11:45 PM 0
Share

It it not breaking a rule. In fact, you should mark it as correct using the currently gray tick mark.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

" Prepare iOS For Recording " on iOS 1 Answer

Unity 4.2 IOS Exception Handling 0 Answers

Unity 4.2.1 iOS 8.2 Orientation issue 0 Answers

4.2 iOS Exceptions Not Printed 2 Answers

Submit to app store rejected for icon sizes and push notification 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges