- Notifications
You must be signed in to change notification settings - Fork226
📱 🆔 iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.
License
fabiocaccamo/FCUUID
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
iOSUUID library as alternative to the old goodUDID andidentifierForVendor.This library provides the simplest API to obtainuniversally unique identifiers with different levels ofpersistence.
It's possible to retrieve theUUIDs created for all devices of the same user, in this way with a little bit of server-side helpit's possible manage guest accounts across multiple devices easily.
- iOS >= 5.0
- ARC enabled
- Key-value storage enabled(target / Capabilities / iCloud / Key-value storage)
- Security.framework
- UICKeyChainStore
- (optional) - Key-value storage enabled -> Target / Capabilities / iCloud / Key-value storage enabled if you want toshare
uuidsOfUserDevices
valuesacross multiple devices using the same iCloud account. - (optional) - KeyChain sharing enabled (entitlements and provisioning profile) if you need toshare the same
uuidForDevice
/uuidsOfUserDevices
valuesacross multiple apps with the same bundle seed.
pod 'FCUUID'
- File > Swift Packages > Add Package Dependency
- Addhttps://github.com/fabiocaccamo/FCUUID
- Select "Up to Next Major" with "1.0.0"
github "fabiocaccamo/FCUUID"
- Copy
FCUUID
folder to your project. - Manual installUICKeyChainStore
It is recommended to do the setup inapplicationDidFinishLaunchingWithOptions
method.
- Add an observer to the
FCUUIDsOfUserDevicesDidChangeNotification
to be notified about uuids of user devices changes. - If necessary,migrate from a previously used UUID or UDID using one of the migrations methods listed in the API section (it's recommended to do migration before calling
uuidForDevice
oruuidsForUserDevices
methods). Keep in mind thatmigration works only if the existing value is a valid uuid anduuidForDevice
has not been created yet. - Call any class method to enforce iCloud sync.
Get different UUIDs (each one with its own persistency level)
//changes each time (no persistent)+(NSString *)uuid;//changes each time (no persistent), but allows to keep in memory more temporary uuids+(NSString *)uuidForKey:(id<NSCopying>)key;//changes each time the app gets launched (persistent to session)+(NSString *)uuidForSession;//changes each time the app gets installed (persistent to installation)+(NSString *)uuidForInstallation;//changes each time all the apps of the same vendor are uninstalled (this works exactly as identifierForVendor)+(NSString *)uuidForVendor;//changes only on system reset, this is the best replacement to the good old udid (persistent to device)+(NSString *)uuidForDevice;//or#import"UIDevice+FCUUID.h"[[UIDevicecurrentDevice]uuid];
Get the list of UUIDs of user devices
//returns the list of all uuidForDevice of the same user, in this way it's possible manage guest accounts across multiple devices easily+(NSArray *)uuidsOfUserDevices;
Migrate from a previously stored UUID / UDIDBefore migrating an existing value it's recommended todebug it by simply passingcommitMigration:NO
and logging the returned value.When you will be ready for committing the migration, usecommitMigration:YES
.After the migration, any future call touuidForDevice
will return the migrated value.
//these methods search for an existing UUID / UDID stored in the KeyChain or in UserDefaults for the given key / service / access-group+(NSString *)uuidForDeviceMigratingValue:(NSString *)value commitMigration:(BOOL)commitMigration;+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key commitMigration:(BOOL)commitMigration;+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key service:(NSString *)service commitMigration:(BOOL)commitMigration;+(NSString *)uuidForDeviceMigratingValueForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup commitMigration:(BOOL)commitMigration;
Check if value is a valid UUID
+(BOOL)uuidValueIsValid:(NSString *)uuidValue;
√
yes-
no*
read notes below
PERSISTS | App memory | App relaunch | Reset Advertising Identifier | App reinstall | System reboot | System upgrade | System reset |
---|---|---|---|---|---|---|---|
uuid | - | - | - | - | - | - | - |
uuidForKey:key | √ | - | - | - | - | - | - |
uuidForSession | √ | - | - | - | - | - | - |
uuidForInstallation | √ | √ | √ | - | √ | - | - |
uuidForVendor | √ | √ | - | √* | √ | - | - |
uuidForDevice | √ | √ | √ | √ | √ | √ | √** |
*(persists only if the user have not uninstalled all apps of the same vendor)
**(persists only if the user restores a device backup which includes also keychain's data)
You must haveKeyChain sharing enabled (entitlements and provisioning profile) and your apps identifiers must have the same bundle seed.
What happens if I calluuidForDevice
on 2 different devices using same iCloud account and iCloud Keychain?
You will obtain 2different uuid(s), and if you calluuidsOfUserDevices
you will obtain a list containing the uuids of both devices.
Please check thepersistence table above.
Released underMIT License.
About
📱 🆔 iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.