- Home /
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?
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 )
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.
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
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...
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?
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.
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).
Your answer
Follow this Question
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