Update device documentation

This commit is contained in:
Daniel Saidi 2021-09-08 11:29:00 +02:00
parent a453a281e9
commit 7410d89f87
3 changed files with 17 additions and 0 deletions

View File

@ -14,6 +14,9 @@ import Foundation
*/
public protocol DeviceIdentifier: AnyObject {
/**
Get a unique device identifier.
*/
func getDeviceIdentifier() -> String
}

View File

@ -29,6 +29,13 @@ public class KeychainBasedDeviceIdentifier: DeviceIdentifier {
private let backupIdentifier: DeviceIdentifier
private let keychainService: KeychainService
/**
Get a unique device identifier from the device keychain.
If no identifier exists in the keychain, the identifier
will use the provided `backupIdentifier` to generate an
identifier, then persist that id in the device keychain.
*/
public func getDeviceIdentifier() -> String {
if let id = keychainService.string(for: key, with: nil) { return id }
let id = backupIdentifier.getDeviceIdentifier()

View File

@ -28,6 +28,13 @@ public class UserDefaultsBasedDeviceIdentifier: DeviceIdentifier {
private let defaults: UserDefaults
/**
Get a unique device identifier from the user defaults.
If no persisted identifier exists, this identifier will
generate a new identifier, then persist and return that
identifier.
*/
public func getDeviceIdentifier() -> String {
if let id = defaults.string(forKey: key) { return id }
return generateDeviceIdentifier()