FCUUID

iOS UUID / 通用唯一标识符库,可以替代 UDID 和 identifierForVendor。「iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.」

Github stars Tracking Chart

FCUUID

iOS UUID 库可以替代旧的良好 UDID 和 identifierForVendor。 该库提供了最简单的 API,以获取具有不同持久性级别的通用唯一标识符。

可以检索为同一用户的所有设备创建的 UUID,通过这种方式在服务器端的帮助下,可以轻松管理多个设备上的来宾帐户。

要求和依赖性

  • 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.

安装

CocoaPods:

pod 'FCUUID'

手动安装:

可选设置:

建议在 applicationDidFinishLaunchingWithOptions 方法中进行设置。

将观察者添加到 FCUUIDsOfUserDevicesDidChangeNotification,以通知用户设备更改的 uuid。

如有必要,请使用 API 部分中列出的一种迁移方法从以前使用的 UUID 或 UDID 进行迁移(建议在调用 uuidForDevice 或 uuidsForUserDevices 方法之前进行迁移)。 请记住,仅当现有值是有效的 uuid 且尚未创建 uuidForDevice 时,迁移才起作用。

调用任何类方法以强制执行 iCloud 同步。

API

获取不同的UUID(每个都有自己的持久性级别)

//changes each time (no persistent)
+(NSString *)uuid;

//changes each time (no persistent), but allows to keep in memory more temporary uuids
+(NSString *)uuidForKey:(id)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];

获取用户设备的 UUID 列表

//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;

从先前存储的 UUID/UDID 迁移在迁移现有值之前,建议通过简单地传递 commitMigration:NO 并记录返回值来对其进行调试。当您准备好提交迁移时,请使用 commitMigration:YES。 迁移后,将来对 uuidForDevice 的任何调用都将返回迁移后的值。

//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;

检查值是否为有效的 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 **

*(仅在用户尚未卸载同一供应商的所有应用程序时持续存在)

**(仅当用户恢复还包括钥匙串数据的设备备份时才持久)

常问问题

如何在两个应用程序之间共享设备 uuid?

您必须启用 KeyChain 共享(权利和配置配置文件),并且您的应用程序标识符必须具有相同的捆绑包种子。

如果我使用相同的 iCloud 帐户和 iCloud 密钥在2个不同的设备上调用uuidForDevice,会发生什么情况?

您将获得2个不同的 uuid,并且如果调用 uuidsOfUserDevices,则将获得一个包含两个设备的 uuid 的列表。

重新启动/升级/重置设备系统后,设备的 uuid 会更改吗?

请检查上面的持久性表。

支持开发

Donate

许可

根据 MIT 许可证发布。


(The first version translated by vz on 2020.07.19)

Main metrics

Overview
Name With Ownerfabiocaccamo/FCUUID
Primary LanguageObjective-C
Program languageObjective-C (Language Count: 3)
PlatformiOS, Mac
License:MIT License
所有者活动
Created At2014-10-06 12:15:00
Pushed At2024-06-14 01:52:21
Last Commit At2022-12-13 15:24:52
Release Count11
Last Release Name1.3.2 (Posted on 2021-02-26 10:23:52)
First Release Name1.0.0 (Posted on 2014-10-06 14:29:56)
用户参与
Stargazers Count1.6k
Watchers Count56
Fork Count226
Commits Count74
Has Issues Enabled
Issues Count31
Issue Open Count3
Pull Requests Count4
Pull Requests Open Count0
Pull Requests Close Count6
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

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'

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