Skip to content

Supporting multiple logged in Users

Joel Levin edited this page Mar 23, 2013 · 2 revisions

ANKClient represents an authenticated session for a single user, so instead of using ANKClient's sharedClient for everything, simply alloc/init an ANKClient for each user and use the correct instance for requests.

Of course, this also means that you need to persist multiple accessTokens across app launches and to set up a new ANKClient for each saved accessToken when the app is launched.

Example

This code:

[[ANKClient sharedClient] createPostWithText:@"test" completion:nil];

becomes something like this:

// somewhere in an app delegate, far far away
NSMutableDictionary *authenticatedClients = [NSMutableDictionary dictionary];
authenticatedClients[@"joeldev"] = [[ANKClient alloc] init];
// set up the client, performing either auth or setting the accessToken

// ...
// meanwhile
// ...

NSString *username; // a username that came from somewhere and is valid
ANKClient *client = authenticatedClients[username];
[client createPostWithText:@"test" completion:nil];