Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (IBAction)TwitterButtonClicked: (UIButton *)sender {
- // Is Twitter accessible and is there at least one account
- // setup on the device
- if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
- //create store and try to get access
- ACAccountStore *account = [[ACAccountStore alloc] init];
- ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
- ACAccountTypeIdentifierTwitter];
- [account requestAccessToAccountsWithType:accountType options:nil
- completion:^(BOOL granted, NSError *error)
- {
- //If user grants the app access
- if (granted == YES)
- {
- //Multiple Twitter accounts present?
- NSArray *arrayOfAccounts = [account
- accountsWithAccountType:accountType];
- for (ACAccount *acc in arrayOfAccounts) {
- [acc accountType].identifier;
- //Otherwise the identifier get lost - god knows why -__-
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([arrayOfAccounts count] > 1)
- {
- self.alertDelegate = [AccountHandler
- initWithAccounts: arrayOfAccounts];
- UIAlertView *message =
- [[UIAlertView alloc] initWithTitle:@"Multiple Accounts Detected!"
- message:@"Please pick the account you used \
- to sign up for ComicBin."
- delegate:[self alertDelegate]
- cancelButtonTitle:@"Cancel"
- otherButtonTitles:nil];
- for (ACAccount *acc in arrayOfAccounts) {
- [message addButtonWithTitle: [acc accountDescription]];
- }
- [message show];
- } else {
- ACAccount *acc = [arrayOfAccounts lastObject];
- //Just one account
- [AccountHandler checkAccountOf:acc];
- }
- });
- } else {
- //Access denied
- UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Access denied"
- message:@"Could not obtain right to use linked \
- Twitter account. Please allow this app access to your Twitter account(s)"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [message show];
- }
- }];
- } else {
- UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"No linked Twitter accounts"
- message:@"It looks like you have not linked \
- any Twitter accounts to your iPhone"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [message show];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement