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
2
Question by DannyB · Aug 20, 2013 at 11:58 AM · iosunique-identifiers

Unique Identifier for both iOS 7 and for older iOS

I am using UnityEngine.SystemInfo.deviceUniqueIdentifier as a part of my encryption and decryption process of sensitive data.

It is my understanding (from reading this thread) that this value will change in iOS 7. For me it will mean that any upgraded device, will be treated as it is a new fresh installation.

Is there any other attribute in Unity I can use that will serve as a (relatively-) unique string and will be the same on iOS 7 and iOS 6 and below?

I have read some posts and answers that suggest saving the device ID in a PlayerPrefs variable, but I fail to understand how this solves the problem. If the ID is saved in prefs, it can be overwritten by anyone, and therefore not serving my purpose.

EDIT:
Found iPhone.vendorIdentifier - would that be an appropriate alternative, and working cross OS version? What will it return in pre iOS 6 devices?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by HeliosDoubleSix · Aug 20, 2013 at 12:49 PM

The reason it is changing in os7 is to make tracking a device impossible so by nature there will be no way to do this by design. Though using the unique device ID as part of encryption is dubiously more secure anyhow. Only thing you can do is change it to a user provided password.

  • New way below using identifierForVendor

  • Note Unity 4 has 'iPhone.vendorIdentifier' built in, but below will work for earlier Unity versions

The vendorIdentifier: "The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes"


Getting UIDevice.identifierForVendor to Unity:

Open Xcode and open the file 'UnityAppController.mm' ( used to be called just AppController.mm in older Unity versions I think )

inside one of the methods/functions ( not sure which is best ) say inside of "- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {"

you can add a call to Unity using UnitySendMessage:

UnitySendMessage("SomeClass", "SomeMethod","stringMessageYouAreSending");

Above would call this class/method in Unity ( remember to add it to an object in your scene ):

 public class SomeClass : MonoBehaviour {
     public void SomeMethod( string message ) {
         
     }
 }

So to get this identifierForvendor insert this code into the UnityAppController.mm inside the method: "- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions"

 if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
         // This is will run if it is iOS6
         NSString *uniqueString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
         UnitySendMessage("SomeClass", "SomeMethod",[uniqueString cStringUsingEncoding:NSUTF8StringEncoding] );
 } else {
         // This is will run before iOS6 and you can insert code here to use openUDID or other method to generate an identifier
 }

( not sure the string conversion here ( cStringUsingEncoding:NSUTF8StringEncoding ) is the best way, but it works )

Comment
Add comment · Show 6 · 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 DannyB · Aug 20, 2013 at 01:02 PM 0
Share

Not so accurate as I see in the Apple docs for UIDevice.identifierForVendor - as far as I understand, this property is unique enough, and is available since iOS 6.

avatar image HeliosDoubleSix · Aug 20, 2013 at 01:33 PM 0
Share

I presumed you'd want the key to stay the same even if someone deletes your app: "The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes" I'll attach an answer for getting that value to Unity seperately

avatar image DannyB · Aug 20, 2013 at 01:36 PM 0
Share

Nope. Dont need the value to stay the same if the app is deleted. The iPhone.vendorIdentifier looked promising, but I just realized it is not available in Unity 3.5...

avatar image DannyB · Aug 21, 2013 at 10:46 AM 0
Share

Ok this is nice. First, I am not sure you saw the edit above - the newer Unity 4.x seem to support vendor identifier out of the box with iPhone.vendorIdentifier - so using this together with uniqueDeviceIdentifier inside Unity only (no xcode) can probably get some good results.

Unfortunately, I have not yet upgraded to Unity 4 due to the never ending crash cases, so the above solution may be suitable for 3.5. I am just a little hesitant to touch the xcode project itself, plus, I will have to redo it every time I do a clean build.

Thoughts?

avatar image HeliosDoubleSix · Aug 21, 2013 at 11:21 AM 0
Share

It's only one file you need to change and will be fine if you just do regular builds, I never need to do a clean build, apart from on Unity upgrades when they change things, then just copy paste that bit of code over again.

Show more comments
avatar image
0

Answer by codestage · Jan 12, 2014 at 06:37 PM

What will it return in pre iOS 6 devices?

Empty string (at least on iOS 5.1.1).

Comment
Add comment · 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

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

17 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 avatar image

Related Questions

How can I get unique identifier IOS in unity? 2 Answers

How to identify each iOS device? 1 Answer

SystemInfo.deviceUniqueIdentifier ready for Limit-Ad-Tracking in iOS 10? 0 Answers

Is there a unique device identifier for ios? 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 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