WAAccountStore 1.3

WAAccountStore 1.3

测试已测试
语言语言 Objective-CObjective C
许可证 MIT
发布最后发布2016年2月

YuAo维护。



 
依赖关系
WAKeyValuePersistenceStore>= 0
UICKeyChainStore>= 0
 

  • 开发者
  • YuAo

WAAccountStore是一个简单而可扩展的帐户系统。

它封装了基本的帐户管理功能,帐户凭证的安全存储。并允许您使用帐户存储任何有用的信息。

基础设施

WAAccount代表一个用户帐户。它包含一个用于存储帐户凭证信息的WAAccountCredential和一个用于存储额外信息的用户信息对象。

WAAccountCredential提供了一种安全存储帐户凭证的方法。它有一个securityStorage属性。在securityStorage中的任何内容都将安全地存储在密钥链中。

WAAccountStore提供了一组帐户管理功能,例如添加帐户、删除帐户、更新帐户等。以及帐户变更通知(WAAccountStoreCurrentAccountDidChangeNotificationWAAccountStoreCurrentAccountUpdatedNotification

使用方法

在整个应用程序中使用默认存储。

WAAccountStore.defaultStore()

您可以直接使用WAAccountStore。但是,创建一些简单的WAAccountCredentialWAAccount扩展将使您的生活更加轻松。

例如

将您的用户模型与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)
    }
}

直接访问WAAccountCredentialsecurityStorage不方便。创建一个扩展以方便访问。

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使用WAKeyValuePersistenceStoreUICKeyChainStore

要求

  • 自动引用计数(ARC)
  • iOS 7.0+
  • Xcode 6.3+