用于 iOS Keychain Services 的包装器,行为类似于 NSUserDefaults
。
将以下文件导入您的项目中,然后 #import
LUKeychainAccess.h
文件。
LUKeychainAccess.h
LUKeychainAccess.m
在您的构建目标“构建相位”下的“链接二进制与库”中添加 Security.framework
。
使用 LUKeychainAccess
就像使用 NSUserDefaults
一样。
[[LUKeychainAccess standardKeychainAccess] setBool:NO forKey:@"authorized"];
BOOL authorized = [[LUKeychainAccess standardKeychainAccess] boolForKey:@"authorized"];
有用于获取和设置 BOOL、double、float 和 NSInteger 类型的方法,以及 NSString
、NSData
和通用的 NSObject
对象。您可以使用可以由 NSKeyedArchiver
编码的任何对象。
Keychain Services 有几个选项,用于确定何时可以读取密钥链项。
此选项可以在 LUKeychainAccess
中通过 accessibilityState
参数设置。其可能的值与 Apple 提供的值相匹配 提供
LUKeychainAccessAttrAccessibleAfterFirstUnlock
LUKeychainAccessAttrAccessibleAfterFirstUnlockThisDeviceOnly
LUKeychainAccessAttrAccessibleAlways
LUKeychainAccessAttrAccessibleAlwaysThisDeviceOnly
LUKeychainAccessAttrAccessibleWhenUnlocked
LUKeychainAccessAttrAccessibleWhenUnlockedThisDeviceOnly
默认值是 LUKeychainAccessAttrAccessibleWhenUnlocked
。
可以可选地给 LUKeychainAccess
一个错误处理器,这是一个实现 LUKeychainErrorHandler
协议的对象。如果发生错误,此错误处理器将会被通知。
LUKeychainAccess
需要 iOS 5.0+。测试是用 Kiwi 编写的。
LUKeychainAccess
由 Costa Walcott 编写,版权为 2012-2013 SCVNGR, Inc D.B.A. LevelUp。这是免费软件,可以根据 MIT-LICENSE 文件中的规定重新分发。