Inherits from NSObject
Declared in DBAccountManager.h

Overview

The account manager is responsible for linking new users and persisting account information across runs of your app. You typically create an account manager at app startup with your app key and secret and keep it until your app terminates.

Tasks

Creating an account manager

Linking new accounts (iOS)

  • – linkFromController:

    (iOS only) This method begins the process for linking new accounts. The user will be prompted to log in and authorize your app. The result is delivered to your app via a URL, and you must call handleOpenURL: to finish linking.

  • – handleOpenURL:

    (iOS only) You must call this method in your app delegate’s -application:openURL:sourceApplication:annotation: method in order to complete the link process.

Linking new accounts (OS X)

Getting the current state

  •   linkedAccount

    The most recently linked account, or nil if there are no accounts currently linked.

    property
  •   linkedAccounts

    All currently linked accounts, or nil if there are no accounts currently linked.

    property

Watching for changes

  • – addObserver:block:

    Add block as an observer to get called whenever a new account is linked or an existing account is unlinked. The observer will be called regardless of whether the account was unlinked using [DBAccount unlink] or by the user on the Dropbox website.

  • – removeObserver:

    Use this method to remove all blocks associated with observer.

Properties

linkedAccount

@property (nonatomic, readonly) DBAccount *linkedAccount
Discussion

The most recently linked account, or nil if there are no accounts currently linked.

If your app needs to link multiple accounts at the same time, you should use the linkedAccounts property.

Declared In

DBAccountManager.h

linkedAccounts

@property (nonatomic, readonly) NSArray *linkedAccounts
Discussion

All currently linked accounts, or nil if there are no accounts currently linked.

The accounts are ordered from the least recently to the most recently linked.

Declared In

DBAccountManager.h

Class Methods

setSharedManager:

+ (void)setSharedManager:(DBAccountManager *)sharedManager
Discussion

A convenient place to store your app’s account manager.

Declared In

DBAccountManager.h

sharedManager

+ (DBAccountManager *)sharedManager
Discussion

A convenient place to get your app’s account manager.

Declared In

DBAccountManager.h

Instance Methods

addObserver:block:

- (void)addObserver:(id)observer block:(DBAccountManagerObserver)block
Discussion

Add block as an observer to get called whenever a new account is linked or an existing account is unlinked. The observer will be called regardless of whether the account was unlinked using [DBAccount unlink] or by the user on the Dropbox website.

Parameters

observer

this is only used as a handle to unregister blocks with the removeObserver: method.

Declared In

DBAccountManager.h

handleOpenURL:

- (DBAccount *)handleOpenURL:(NSURL *)url
Discussion

(iOS only) You must call this method in your app delegate’s -application:openURL:sourceApplication:annotation: method in order to complete the link process.

Return Value

The account object if the link was successful, or nil if the user cancelled.

Declared In

DBAccountManager.h

initWithAppKey:secret:

- (id)initWithAppKey:(NSString *)key secret:(NSString *)secret
Discussion

Create a new account manager with your app’s app key and secret. You can register your app or find your key at the apps ) page.

Declared In

DBAccountManager.h

linkFromController:

- (void)linkFromController:(UIViewController *)rootController
Discussion

(iOS only) This method begins the process for linking new accounts. The user will be prompted to log in and authorize your app. The result is delivered to your app via a URL, and you must call handleOpenURL: to finish linking.

Your app can call this method repeatedly to link more than one account (such as personal and a business account).

Parameters

rootController

the topmost view controller in your controller hierarchy.

Declared In

DBAccountManager.h

linkFromWindow:withCompletionBlock:

- (void)linkFromWindow:(NSWindow *)parentWindow withCompletionBlock:(DBLinkCompletionBlock)block
Discussion

(OS X only) This method begins the process for linking new accounts.

This will open the auth flow in a sheet. If parentWindow is nil it will open in a new window. When the user exits the flow, block will be called with the linked account which might be nil if the user cancelled or if there were errors.

Your app can call this method repeatedly to link more than one account (such as personal and a business account).

Parameters

parentWindow

the parent window the auth flow modal should be attached to.

block

the block that gets called when the user is done linking.

Declared In

DBAccountManager.h

removeObserver:

- (void)removeObserver:(id)observer
Discussion

Use this method to remove all blocks associated with observer.

Parameters

observer

the same value you provided to the addObserver:block: method.

Declared In

DBAccountManager.h