DefaultDeviceIdentifier
public actor DefaultDeviceIdentifier : DeviceIdentifier, Sendable
Default implementation that generates and persists a device identifier.
Implements DeviceIdentifier protocol to provide a unique identifier for the device.
Example usage:
let deviceId = DefaultDeviceIdentifier()
let identifier = try await deviceId.id
// In case of migration from the FR SDK when using a custom Keychain Access Group use the following
func setupDeviceIdentifierWithMigration() async throws -> String {
// If your legacy FRAuth SDK used a custom keychain access group,
// specify it here to enable migration
let configuration = DeviceIdentifierConfiguration(
keySize: DeviceIdentifierConfiguration.default.keySize,
keychainAccount: DeviceIdentifierConfiguration.default.keychainAccount,
useEncryption: DeviceIdentifierConfiguration.default.useEncryption,
legacyKeychainAccessGroup: "com.test" // Set Legacy Keychain Access Group
)
// Initialize with configuration
let deviceIdentifier = try DefaultDeviceIdentifier(
configuration: configuration,
logger: LogManager.standard // Optional: for debugging migration
)
// First access will trigger migration if legacy identifier exists
let deviceId = try await deviceIdentifier.id
print("Device ID: \(deviceId)")
return deviceId
}
-
idAsynchronousThe unique identifier for the device. This identifier is either retrieved from the keychain or generated if it does not exist.
Declaration
Swift
public var id: String { get async throws } -
Initializes a new instance of
DefaultDeviceIdentifierwith custom configuration.Declaration
Swift
public init(configuration: DeviceIdentifierConfiguration = .default, logger: Logger? = nil) throwsParameters
configurationConfiguration for device identifier behavior
loggerAn optional logger to log events. Defaults to
nil. -
Initializes with custom storage (for testing or advanced use cases)
Note
When using custom storage, configuration settings for keychain are ignoredDeclaration
Swift
public init(configuration: DeviceIdentifierConfiguration = .default, storage: any Storage<DeviceIdentifierImpl>, logger: Logger? = nil) -
Clears the cached identifier.
Declaration
Swift
public func clearCache() -
regenerateIdentifier()AsynchronousAsynchronously regenerates the device identifier by deleting the existing keychain item. This method cancels any ongoing generation task and clears the cache. Also clears any legacy identifier storage to ensure a completely new identifier is generated.
Throws
DeviceIdentifierErrorif keychain operations fail.Declaration
Swift
public func regenerateIdentifier() async throws -> StringReturn Value
The new unique identifier for the device.
View on GitHub