我正在使用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
框架是没有人使用的遗产?