Swift鑰匙串KeychainSwift的使用
阿新 • • 發佈:2018-12-15
pod 'KeychainSwift', '12.0.0'
import Foundation import KeychainSwift class KeyChainManager { static let shared = KeyChainManager.init() private let keychain = KeychainSwift(keyPrefix: Dex4DKeys.keychainKeyPrefix) private let option = KeychainSwiftAccessOptions.accessibleWhenUnlockedThisDeviceOnly private let pinKey = "AppPin" var hasPin: Bool { if let _ = getPin() { return true } else { return false } } func getPin() -> String? { return keychain.get(pinKey) } func setPin(value: String) { keychain.set(value, forKey: pinKey, withAccess: option) } func getValue(for key: String) -> String? { return keychain.get(key) } func set(value: String, for key: String) { keychain.set(value, forKey: key, withAccess: option) } }