Giter Site home page Giter Site logo

idtwitteraccountchooserviewcontroller's Introduction

IDTwitterAccountChooserViewController

Twitter Account Chooser view controller for iOS 6+. Uses a block-based completion handler or a classic protocol-based delegate method.

Why?

In iOS 6 and up you can store system-wide Twitter accounts. I looked for an existing Account chooser for when you have multiple accounts and I couldn't find one so I decided to make my own.

What does it looks like?

IDTwitterAccountChooserViewController

It has a very basic look but it can be easily customized via standard UITableViewCell subclassing (or whatever your favorite method is).

How does it works?

Copy and add the IDTwitterAccountChooserViewController.h and IDTwitterAccountChooserViewController.m files to your project, and make sure to link against the Social and Accounts frameworks.

In your own view controller implementation file (.m):

#import <Social/Social.h>
#import <Accounts/Accounts.h>
#import "IDTwitterAccountChooserViewController.h"

...

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// check for access etc.
NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
if([twitterAccounts count] > 1) {
	// more than one account, use Chooser
	IDTwitterAccountChooserViewController *chooser = [[IDTwitterAccountChooserViewController alloc] init];
	[chooser setTwitterAccounts:twitterAccounts];
	[chooser setCompletionHandler:^(ACAccount *account) {
		// if user cancels the chooser then 'account' will be set to nil
		NSLog(@"account chosen: %@", account);
	}];
	[self presentModalViewController:chooser animated:YES];
}

If you'd rather use a protocol based delegation pattern instead of a completion handler block:

// make your view controller conform to the <IDTwitterAccountChooserViewControllerDelegate> protocol
@interface MyOwnViewController <IDTwitterAccountChooserViewControllerDelegate>

...

	[chooser setAccountChooserDelegate:self];

...

// implement the <IDTwitterAccountChooserViewControllerDelegate> method

#pragma mark - <IDTwitterAccountChooserViewControllerDelegate> Methods

- (void)twitterAccountChooserViewController:(IDTwitterAccountChooserViewController *)controller didChooseTwitterAccount:(ACAccount *)account {
		// if user cancels the chooser then 'account' will be set to nil
		NSLog(@"account chosen: %@", account);
}

If you set both a completion handler and a delegate, the former will be called while the later will be ignored.

License

Licensed under the MIT license

Copyright by @iDevSoftware 2012

idtwitteraccountchooserviewcontroller's People

Contributors

dekelev avatar idevsoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

idtwitteraccountchooserviewcontroller's Issues

EXC_BAD_ACCESS for ViewController using iOS 5.1.1

When the Demo project is deployed to an iPad running iOS 5.1.1, there is an EXC_BAD_ACCESS in the initWithNibName:nibNameOrNil bundle:nibBundleOrNil method.

There is no issue when there's only one account in the system, as it shows the "Only a single account is setup" alert view, but when it needs to initialize and show the IDTwitterAccountChooserViewController the app keeps looping in the aforementioned method.
captura de pantalla 2013-10-28 a la s 13 42 10

There is no issue using iOS 6 or 7.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.