Back to rankings

fabiocaccamo/FCUUID

Objective-C

:iphone: :id:  iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.

uuidudidpersistencedeviceunique-identifieriosobjective-cuuidspodsessioninstallationvendor
Star Growth
Stars
1.6k
Forks
236
Weekly Growth
Issues
3
5001k1.5k
Oct 2014Sep 2018Aug 2022Jul 2026
README

FCUUID Pod version Pod platforms Pod license

iOS UUID library as alternative to the old good UDID and identifierForVendor. This library provides the simplest API to obtain universally unique identifiers with different levels of persistence.

It's possible to retrieve the UUIDs created for all devices of the same user, in this way with a little bit of server-side help it's possible manage guest accounts across multiple devices easily.

Requirements & dependencies

  • 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 to share uuidsOfUserDevices values across multiple devices using the same iCloud account.
  • (optional) - KeyChain sharing enabled (entitlements and provisioning profile) if you need to share the same uuidForDevice / uuidsOfUserDevices values across multiple apps with the same bundle seed.

Installation

CocoaPods:

pod 'FCUUID'

Swift Package Manager:

  1. File > Swift Packages > Add Package Dependency
  2. Add https://github.com/fabiocaccamo/FCUUID
  3. Select "Up to Next Major" with "1.0.0"

Carthage:

github "fabiocaccamo/FCUUID"

Manual install:

Optional setup:

It is recommended to do the setup in applicationDidFinishLaunchingWithOptions 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 or uuidsForUserDevices methods). Keep in mind that migration works only if the existing value is a valid uuid and uuidForDevice has not been created yet.
  • Call any class method to enforce iCloud sync.

API

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"
[[UIDevice currentDevice] 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 / UDID Before migrating an existing value it's recommended to debug it by simply passing commitMigration:NO and logging the returned value. When you will be ready for committing the migration, use commitMigration:YES. After the migration, any future call to uuidForDevice 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;

Persistence

  • 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)*

FAQ

How can I share the device uuid between two apps?

You must have KeyChain sharing enabled (entitlements and provisioning profile) and your apps identifiers must have the same bundle seed.

What happens if I call uuidForDevice on 2 different devices using same iCloud account and iCloud Keychain?

You will obtain 2 different uuid(s), and if you call uuidsOfUserDevices you will obtain a list containing the uuids of both devices.

When I reboot / upgrade / reset my device system, will device uuid change?

Please check the persistence table above.

Support development

Donate

License

Released under MIT License.

Related repositories
ramsey/uuid

:snowflake: A PHP library for generating universally unique identifiers (UUIDs).

PHPPackagistMIT Licenseuuidguid
uuid.ramsey.dev
12.6k527
google/uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.

GoGo ModulesBSD 3-Clause "New" or "Revised" Licensegouuid
6.1k431
segmentio/ksuid

K-Sortable Globally Unique IDs

GoGo ModulesMIT Licenseksuidgolang
segment.com/blog/a-brief-history-of-the-uuid/
5.3k199
satori/go.uuid

UUID package for Go

GoGo ModulesMIT Licensegouuid
4.9k594
jetify-com/typeid

Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs

GoGo ModulesApache License 2.0guiduuid
3.6k52
ulid/javascript

Universally Unique Lexicographically Sortable Identifier

TypeScriptnpmMIT Licenseuuidulid
3.4k115
gzu-liyujiang/Android_CN_OAID

安卓设备唯一标识解决方案,可替代移动安全联盟(MSA)统一 SDK 闭源方案。包括国内手机厂商的开放匿名标识(OAID)、海外手机平台的安卓广告标识(AAID),另外也提供了 IMEI/MEID、AndroidID、WidevineID、PseudoID、GUID 等常见的设备标识的获取方法。

JavaMavenOtheroaidguid
gzu-liyujiang.github.io/Android_CN_OAID/
2.8k464
gofrs/uuid

A UUID package for Go

GoGo ModulesMIT Licensegouuid-generator
1.8k124
webpatser/laravel-uuid

Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.

PHPPackagistuuidphp
1.8k150
matoous/go-nanoid

Golang random IDs generator.

GoGo ModulesMIT Licenseunique-iduuid
1.6k64
xiaoyaoyou1212/BLE

✨Android BLE基础操作框架,基于回调,操作简单。包含扫描、多连接、广播包解析、服务读写及通知等功能。

JavaMavenApache License 2.0bleuuid
huwei.tech
1.4k362
lithammer/shortuuid

A generator library for concise, unambiguous and URL-safe UUIDs

GoGo ModulesMIT Licenseshortuuiduuid
pkg.go.dev/github.com/lithammer/shortuuid/v4
1.4k63