Mac Developer Library

Developer

Accounts Framework Reference ACAccountStore Class Reference

Options
Deployment Target:

On This Page
Language:

ACAccountStore

Inheritance


Conforms To


Import Statement


Swift

import Accounts

Objective-C

@import Accounts;

Availability


Available in OS X v10.8 and later.

The ACAccountStore class provides an interface for accessing, manipulating, and storing accounts. To create and retrieve accounts from the Accounts database, you must create an ACAccountStore object. Each ACAccount object belongs to a single ACAccountStore object.

  • accounts accounts Property

    The accounts managed by this account store. (read-only)

    Declaration

    Swift

    var accounts: [AnyObject]! { get }

    Objective-C

    @property(readonly, weak, atomic) NSArray *accounts

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Returns the account with the specified identifier.

    Declaration

    Swift

    func accountWithIdentifier(_ identifier: String!) -> ACAccount!

    Objective-C

    - (ACAccount *)accountWithIdentifier:(NSString *)identifier

    Parameters

    identifier

    A unique identifier for an account.

    Return Value

    The account that matches the value specified in identifier.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

    See Also

    identifier

  • Returns all accounts of the specified type.

    Declaration

    Swift

    func accountsWithAccountType(_ accountType: ACAccountType!) -> [AnyObject]!

    Objective-C

    - (NSArray *)accountsWithAccountType:(ACAccountType *)accountType

    Parameters

    accountType

    The type of an account.

    Return Value

    All accounts that match accountType.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

    See Also

    accountType

  • Returns an account type that matches the specified identifier.

    Declaration

    Swift

    func accountTypeWithAccountTypeIdentifier(_ typeIdentifier: String!) -> ACAccountType!

    Objective-C

    - (ACAccountType *)accountTypeWithAccountTypeIdentifier:(NSString *)typeIdentifier

    Parameters

    typeIdentifier

    The account type identifier.

    Return Value

    An account type that matches typeIdentifier.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Saves an account to the Accounts database.

    Declaration

    Swift

    func saveAccount(_ account: ACAccount!, withCompletionHandler completionHandler: ACAccountStoreSaveCompletionHandler!)

    Objective-C

    - (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler

    Parameters

    account

    The account to save.

    completionHandler

    The handler to call when the operation is done. The handler is called on an arbitrary queue.

    Discussion

    If the account type supports authentication and the account is not authenticated, the account server uses the account's credentials to authenticate it. If the authentication is successful, the account is saved; otherwise it is not saved.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Obtains permission to access protected user properties.

    Declaration

    Swift

    func requestAccessToAccountsWithType(_ accountType: ACAccountType!, options options: [NSObject : AnyObject]!, completion completion: ACAccountStoreRequestAccessCompletionHandler!)

    Objective-C

    - (void)requestAccessToAccountsWithType:(ACAccountType *)accountType options:(NSDictionary *)options completion:(ACAccountStoreRequestAccessCompletionHandler)completion

    Parameters

    accountType

    The account type.

    options

    The account type.

    completion

    The handler to call when the request has completed. The handler is called on an arbitrary queue.

    Discussion

    Certain account types (such as Facebook) require an options dictionary. This method will throw an NSInvalidArgumentException if the options dictionary is not provided for such account types. Conversely, if the account type does not require an options dictionary, the options parameter must be nil.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Renews account credentials when the credentials are no longer valid.

    Declaration

    Swift

    func renewCredentialsForAccount(_ account: ACAccount!, completion completionHandler: ACAccountStoreCredentialRenewalHandler!)

    Objective-C

    - (void)renewCredentialsForAccount:(ACAccount *)account completion:(ACAccountStoreCredentialRenewalHandler)completionHandler

    Parameters

    account

    The account to renew credentials.

    completionHandler

    The handler to call when the renewal has completed.

    Discussion

    For Twitter and Sina Weibo accounts, this method will prompt the user to go to Settings to re-enter their password.

    For Facebook accounts, if the access token has become invalid due to a regular expiration, this method will obtain a new one.

    If the user has deauthorized your app, this renewal request will return ACAccountCredentialRenewResultRejected.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Removes an account from the account store.

    Declaration

    Swift

    func removeAccount(_ account: ACAccount!, withCompletionHandler completionHandler: ACAccountStoreRemoveCompletionHandler!)

    Objective-C

    - (void)removeAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreRemoveCompletionHandler)completionHandler

    Parameters

    account

    The account to remove.

    completionHandler

    The handler to call when the removal has completed.

    Discussion

    This call will fail if you don't have sufficient rights to remove the account.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

Data Types

  • Specifies a handler to call when an Accounts database operation is complete.

    Declaration

    Swift

    typealias ACAccountStoreSaveCompletionHandler = (Bool, NSError!) -> Void

    Objective-C

    typedef void(^ACAccountStoreSaveCompletionHandler)(BOOL success, NSError *error);

    Discussion

    The completion handler parameters are:

    success

    A Boolean value indicating whether the operation is successful. YEStrue if the operation is successful; otherwise NOfalse.

    error

    An error, if one occurred.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Specifies a handler to call when an account is removed from the store.

    Declaration

    Swift

    typealias ACAccountStoreRemoveCompletionHandler = (Bool, NSError!) -> Void

    Objective-C

    typedef void(^ACAccountStoreRemoveCompletionHandler)(BOOL success, NSError *error);

    Discussion

    The completion handler parameters are:

    success

    A Boolean value indicating whether the operation was successful. YEStrue if successful; otherwise NOfalse.

    error

    An error, if one occurred.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Specifies a handler to call when access is granted or denied.

    Declaration

    Swift

    typealias ACAccountStoreRequestAccessCompletionHandler = (Bool, NSError!) -> Void

    Objective-C

    typedef void(^ACAccountStoreRequestAccessCompletionHandler)(BOOL granted, NSError *error);

    Discussion

    The completion handler parameters are:

    granted

    A Boolean value indicating whether access is granted. YEStrue if access is granted; otherwise NOfalse.

    error

    An error, if one occurred.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Specifies a handler to call when credentials are renewed.

    Declaration

    Swift

    typealias ACAccountStoreCredentialRenewalHandler = (ACAccountCredentialRenewResult, NSError!) -> Void

    Objective-C

    typedef void(^ACAccountStoreCredentialRenewalHandler)(ACAccountCredentialRenewResult renewResult, NSError *error);

    Discussion

    The renewal handler parameters are:

    renewResult

    The result of the renewal request.

    error

    An error, if one occurred.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Options dictionary keys supporting requests to Facebook accounts.

    Declaration

    Swift

    let ACFacebookAppIdKey: String let ACFacebookPermissionsKey: String let ACFacebookAudienceKey: String

    Objective-C

    NSString *ACFacebookAppIdKey; NSString *ACFacebookPermissionsKey; NSString *ACFacebookAudienceKey;

    Constants

    • ACFacebookAppIdKey

      ACFacebookAppIdKey

      The Facebook App ID, as it appears on the Facebook website.

      Available in OS X v10.8 and later.

    • ACFacebookPermissionsKey

      ACFacebookPermissionsKey

      The array of strings of permissions to request (e.g. email, publish_stream, etc.).

      Available in OS X v10.8 and later.

    • ACFacebookAudienceKey

      ACFacebookAudienceKey

      Only required when posting permissions are requested.

      Available in OS X v10.8 and later.

  • Options dictionary values supporting requests to Facebook accounts.

    Declaration

    Swift

    let ACFacebookAudienceEveryone: String let ACFacebookAudienceFriends: String let ACFacebookAudienceOnlyMe: String

    Objective-C

    NSString *ACFacebookAudienceEveryone; NSString *ACFacebookAudienceFriends; NSString *ACFacebookAudienceOnlyMe;

    Constants

    • ACFacebookAudienceEveryone

      ACFacebookAudienceEveryone

      Posts are visible to everyone.

      Available in OS X v10.8 and later.

    • ACFacebookAudienceFriends

      ACFacebookAudienceFriends

      Posts are visible only to friends.

      Available in OS X v10.8 and later.

    • ACFacebookAudienceOnlyMe

      ACFacebookAudienceOnlyMe

      Posts are visible to the user only.

      Available in OS X v10.8 and later.

  • Options dictionary keys supporting requests to LinkedIn accounts.

    Declaration

    Swift

    let ACLinkedInAppIdKey: String let ACLinkedInPermissionsKey: String

    Objective-C

    NSString *ACLinkedInAppIdKey; NSString *ACLinkedInPermissionsKey;

    Constants

    • ACLinkedInAppIdKey

      ACLinkedInAppIdKey

      The LinkedIn App ID, as it appears on the LinkedIn website.

      Available in OS X v10.9 and later.

    • ACLinkedInPermissionsKey

      ACLinkedInPermissionsKey

      The array of strings of permissions to request.

      Available in OS X v10.9 and later.

  • Options dictionary keys supporting requests to Tencent Weibo accounts.

    Declaration

    Swift

    let ACTencentWeiboAppIdKey: String

    Objective-C

    NSString *ACTencentWeiboAppIdKey;

    Constants

    • ACTencentWeiboAppIdKey

      ACTencentWeiboAppIdKey

      The Tencent Weibo App ID, as it appears on the Tencent Weibo website.

      Available in OS X v10.9 and later.

  • Status codes of credential renewal requests.

    Declaration

    Swift

    enum ACAccountCredentialRenewResult : Int { case Renewed case Rejected case Failed }

    Objective-C

    typedef enum { ACAccountCredentialRenewResultRenewed, ACAccountCredentialRenewResultRejected, ACAccountCredentialRenewResultFailed } ACAccountCredentialRenewResult;

    Constants

    • Renewed

      ACAccountCredentialRenewResultRenewed

      The account’s credentials have been renewed and are now associated with the account.

      Available in OS X v10.8 and later.

    • Rejected

      ACAccountCredentialRenewResultRejected

      Renewal failed because the user revoked your access to their account.

      Available in OS X v10.8 and later.

    • Failed

      ACAccountCredentialRenewResultFailed

      A non-user-initiated cancel of the prompt. Try again.

      Available in OS X v10.8 and later.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.

  • Posted when the accounts managed by this account store changed in the database. There is no userInfo dictionary associated with this notification.

    This notification is sent if an account is saved or removed locally or externally. If you receive this notification, you should refetch all account objects.

    Import Statement

    Objective-C

    @import Accounts;

    Swift

    import Accounts

    Availability

    Available in OS X v10.8 and later.