Update device documentation
This commit is contained in:
parent
a453a281e9
commit
7410d89f87
|
@ -14,6 +14,9 @@ import Foundation
|
|||
*/
|
||||
public protocol DeviceIdentifier: AnyObject {
|
||||
|
||||
/**
|
||||
Get a unique device identifier.
|
||||
*/
|
||||
func getDeviceIdentifier() -> String
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue