ACAccountStore Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Accounts.framework
Availability
Available in OS X v10.8 and later.
Declared in
ACAccountStore.h
ACAccountType.h

Overview

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.

Tasks

Getting Accounts

Getting Account Types

Saving Accounts

Requesting Access

Renewing Account Credentials

Removing Accounts

Properties

accounts

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

@property(nonatomic, readonly) NSArray *accounts
Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

Instance Methods

accountsWithAccountType:

Returns all accounts of the specified type.

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

The type of an account.

Return Value

All accounts that match accountType.

Availability
  • Available in OS X v10.8 and later.
See Also
Declared In
ACAccountStore.h

accountTypeWithAccountTypeIdentifier:

Returns an account type that matches the specified identifier.

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

The account type identifier.

Return Value

An account type that matches typeIdentifier.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

accountWithIdentifier:

Returns the account with the specified identifier.

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

A unique identifier for an account.

Return Value

The account that matches the value specified in identifier.

Availability
  • Available in OS X v10.8 and later.
See Also
Declared In
ACAccountStore.h

removeAccount:withCompletionHandler:

Removes an account from the account store.

- (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.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

renewCredentialsForAccount:completion:

Renews account credentials when the credentials are no longer valid.

- (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.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

requestAccessToAccountsWithType:options:completion:

Obtains permission to access protected user properties.

- (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.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

saveAccount:withCompletionHandler:

Saves an account to the Accounts database.

- (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.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

Constants

Facebook Access Keys

Options dictionary keys supporting requests to Facebook accounts.

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

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

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

ACFacebookPermissionsKey

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

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

ACFacebookAudienceKey

Only required when posting permissions are requested.

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

Facebook Access Values

Options dictionary values supporting requests to Facebook accounts.

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

Posts are visible to everyone.

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

ACFacebookAudienceFriends

Posts are visible only to friends.

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

ACFacebookAudienceOnlyMe

Posts are visible to the user only.

Available in OS X v10.8 and later.

Declared in ACAccountType.h.

LinkedIn Access Keys

Options dictionary keys supporting requests to LinkedIn accounts.

NSString *ACLinkedInAppIdKey;
NSString *ACLinkedInPermissionsKey;
Constants
ACLinkedInAppIdKey

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

Available in OS X v10.9 and later.

Declared in ACAccountType.h.

ACLinkedInPermissionsKey

The array of strings of permissions to request.

Available in OS X v10.9 and later.

Declared in ACAccountType.h.

Tencent Weibo Access Keys

Options dictionary keys supporting requests to Tencent Weibo accounts.

NSString *ACTencentWeiboAppIdKey;
Constants
ACTencentWeiboAppIdKey

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

Available in OS X v10.9 and later.

Declared in ACAccountType.h.

Credential Renewal Results

Status codes of credential renewal requests.

typedef enum {
   ACAccountCredentialRenewResultRenewed,
   ACAccountCredentialRenewResultRejected,
   ACAccountCredentialRenewResultFailed
} ACAccountCredentialRenewResult;
Constants
ACAccountCredentialRenewResultRenewed

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

Available in OS X v10.8 and later.

Declared in ACAccountStore.h.

ACAccountCredentialRenewResultRejected

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

Available in OS X v10.8 and later.

Declared in ACAccountStore.h.

ACAccountCredentialRenewResultFailed

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

Available in OS X v10.8 and later.

Declared in ACAccountStore.h.

ACAccountStoreSaveCompletionHandler

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

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

The completion handler parameters are:

success

A Boolean value indicating whether the operation is successful. YES if the operation is successful; otherwise NO.

error

An error, if one occurred.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

ACAccountStoreRemoveCompletionHandler

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

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

The completion handler parameters are:

success

A Boolean value indicating whether the operation was successful. YES if successful; otherwise NO.

error

An error, if one occurred.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

ACAccountStoreRequestAccessCompletionHandler

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

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

The completion handler parameters are:

granted

A Boolean value indicating whether access is granted. YES if access is granted; otherwise NO.

error

An error, if one occurred.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

ACAccountStoreCredentialRenewalHandler

Specifies a handler to call when credentials are renewed.

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.

Availability
  • Available in OS X v10.8 and later.
Declared In
ACAccountStore.h

Notifications

ACAccountStoreDidChangeNotification

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.

Availability
Declared In
ACAccountStore.h