我可以使用帐户框架进行自定义登录吗?

时间:2018-06-06 13:47:39

标签: ios swift oauth-2.0 account

我正在使用OAuth2身份验证,并希望使用Accounts框架。除了我无法访问refreshToken中的ACAccountCredential属性外,一切看起来都不错。

@available(iOS 5.0, *)
open class ACAccountCredential : NSObject {
    public init!(oAuthToken token: String!, tokenSecret secret: String!)
    public init!(oAuth2Token token: String!, refreshToken: String!, expiryDate: Date!)

    // This property is only valid for OAuth2 credentials
    open var oauthToken: String!
}

要更新accessToken,我似乎需要使用ACAccountStore

@available(iOS 5.0, *)
open class ACAccountStore : NSObject {
    // Saves the account to the account database. If the account is unauthenticated and the associated account
    // type supports authentication, the system will attempt to authenticate with the credentials provided.
    // Assuming a successful authentication, the account will be saved to the account store. The completion handler
    // for this method is called on an arbitrary queue.
    open func saveAccount(_ account: ACAccount!, withCompletionHandler completionHandler: ACAccountStoreSaveCompletionHandler!)

    open func requestAccessToAccounts(with accountType: ACAccountType!, options: [AnyHashable : Any]! = [:], completion: ACAccountStoreRequestAccessCompletionHandler!)


    // Call this if you discover that an ACAccount's credential is no longer valid.
    open func renewCredentials(for account: ACAccount!, completion completionHandler: ACAccountStoreCredentialRenewalHandler!)
}

ACAccountStore中有几件事情并不那么清楚。什么是account database?它是一个钥匙串,所以我也可以在其他应用程序中使用?或者它是一种私人CoreData数据库?

我创建了一个子类来覆盖renewCredential,但问题是我无法访问refreshToken中的ACAccountCrendential值。我做对了吗?或者这个Accounts框架是没有人使用的遗产?

0 个答案:

没有答案