测试已测试 | ✗ |
语言语言 | Objective-CObjective C |
许可证 | MIT |
发布最后发布 | 2016年2月 |
由YuAo维护。
依赖关系 | |
WAKeyValuePersistenceStore | >= 0 |
UICKeyChainStore | >= 0 |
WAAccountStore
是一个简单而可扩展的帐户系统。
它封装了基本的帐户管理功能,帐户凭证的安全存储。并允许您使用帐户存储任何有用的信息。
WAAccount
代表一个用户帐户。它包含一个用于存储帐户凭证信息的WAAccountCredential
和一个用于存储额外信息的用户信息对象。
WAAccountCredential
提供了一种安全存储帐户凭证的方法。它有一个securityStorage
属性。在securityStorage
中的任何内容都将安全地存储在密钥链中。
WAAccountStore
提供了一组帐户管理功能,例如添加帐户、删除帐户、更新帐户等。以及帐户变更通知(WAAccountStoreCurrentAccountDidChangeNotification
,WAAccountStoreCurrentAccountUpdatedNotification
)
在整个应用程序中使用默认存储。
WAAccountStore.defaultStore()
您可以直接使用WAAccountStore
。但是,创建一些简单的WAAccountCredential
和WAAccount
扩展将使您的生活更加轻松。
例如
将您的用户模型与WAAccount
关联。
//Assuming `User` is your user model class.
extension WAAccount {
var user: User {
get {
return self.userInfo as! User
}
}
convenience init(identifier: String, credential: WAAccountCredential, user: User) {
self.init(identifier: identifier, credential: credential, userInfo: user)
}
}
直接访问WAAccountCredential
的securityStorage
不方便。创建一个扩展以方便访问。
let UserAccessTokenStorageKey = "AccessToken"
extension WAAccountCredential {
var accessToken: String {
get {
return self.securityStorage[UserAccessTokenStorageKey] as! String
}
}
convenience init(identifier: String, accessToken: String) {
self.init(identifier: identifier, securityStorage: [UserAccessTokenStorageKey: accessToken])
}
}
在WAAccountStoreDemo文件夹中有一个简单的演示项目。打开并构建WAAccountStoreDemo.xcworkspace
需要执行pod install
。
您可以选择克隆仓库并将WAAccountStore
目录中的文件手动添加
或者如果您使用Cocoapods,请将以下内容添加到您的Podfile中
pod 'WAAccountStore'
WAAccountStore
使用WAKeyValuePersistenceStore
和UICKeyChainStore