How should I use identifierForVendor during development?
Asked Answered
R

2

11

Apple recommends using [UIDevice currentDevice].identifierForVendor. The value of this changes every time one runs their application within the iOS simulator.

Initial functionality in my application requires that I recognize the device as a form of light authentication. This makes development tedious, and ideally I could persist a unique value across debug / run sessions. Are there any recommendations for accomplishing this?

Revolting answered 19/9, 2013 at 21:19 Comment(0)
P
19

It's pretty clearly documented that this value will change when building and running in the simulator. On a real device, it will only change when the user deletes all of your apps from their device and reinstalls the app.

If you want the simulator app to use a consistent identifier during development you could define that UUID and use it for simulator builds only:

NSUUID *devId;
#if TARGET_IPHONE_SIMULATOR
devId = [NSUUID initWithUUIDString:@"SOME-STATIC-UUID-STRING"];
#else
devId = [UIDevice currentDevice].identifierForVendor;
#endif

Note that you need to replace SOME-STATIC-UUID-STRING with a real UUID string.

Passably answered 19/9, 2013 at 21:36 Comment(8)
Hi Ryan. Yes I understand that this is unique to the simulator. I'm asking how others have worked around it during development.Revolting
Usually I have built apps so that they don't depend on that property for anything critical (usually just a caching of a login token by device). If you absolutely need it, generate a UUID once and use that in a bit of conditional compilation (updating my answer to show you what this would look like) for the simulator builds.Passably
Ryan, thanks for the update. I had implemented something similar, and I'll update the question to reflect, because it isn't effective in a team environment. Perhaps my approach is wrong, or this will just be like testing notifications, which isn't possible in the simulator.Revolting
By the way, your target check is cleaner than my string check obviously, so thanks.Revolting
If you're depending on the identifierForVendor for something that critical that you really need it to be different for every developer, you may have a bad time of it when the app is in production. Simply reinstalling the app or restoring from a backup will reset that identifier.Passably
I'm starting to see identifierForVendor reset randomly on my Enterprise Distribution apps now, even without deletion of the app or restore. I'm moving toward a Keychain key approach now.Latticed
Yep, Bek - I have never had a consistent identifierForVendor for my enterprise apps. Each app gets its own identifierForVendor. I have submitted a bug report to Apple (like 6 months ago) and haven't heard anything back. Can you share your keychain approach? I was leaning toward using NSUUID and storing it.Strategy
The link OP added mentioned nothing about idFresno
F
0

As of May 8, 2023

identifierForVendor

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

Reference

My guess is that every time we kill simulator and start again, we get a new "phone", so a new device Id.

Fresno answered 8/5, 2023 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.