Abhishek
Abhishek

Reputation: 1702

iOS Twitter Integration

I want to integrate twitter in my application, mostly that will use for login purpose, I want to implement it like following case

  1. Check if there are any twitter account already linked with phone use that with reverse authentication
  2. If no account linked, Use some OAuth library for twitter and make authentication with that

Anyone have idea about any existing library/framework doing the same ? Thanks

P.S : Minimum supported iOS version would be iOS6

Upvotes: 0

Views: 250

Answers (2)

Alok Singh
Alok Singh

Reputation: 896

https://github.com/aryansbtloe/LoginViaSocialMedias

This is an example project for adding login via facebook,twitter,google plus and four square support to your ios application.

Upvotes: 0

Ashutosh
Ashutosh

Reputation: 2225

You can use below code: (If no account is found from settings, then this will take your application to settings screen of device):

- (IBAction)loginWithTwitterBtn:(id)sender
{
    if ([TWTweetComposeViewController canSendTweet])
    {
        //yes user is logged in
        accountStore = [[ACAccountStore alloc] init];
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

        // Request access from the user to use their Twitter accounts.
        [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
         {
             // Did user allow us access?
             if (granted == YES)
             {
                 // Populate array with all available Twitter accounts
                 NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];

                 ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

                 // Set the cell text to the username of the twitter account
                 NSString *userID = [[acct valueForKey:@"properties"] valueForKey:@"user_id"];

             }
         }];
    }
    else
    {
        //show tweeet login prompt to user to login
        TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];

        //hide the tweet screen
        viewController.view.hidden = YES;

        //fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
        viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
            if (result == TWTweetComposeViewControllerResultCancelled) {
                [self dismissModalViewControllerAnimated:NO];
            }
        };
        [self presentModalViewController:viewController animated:NO];

        //hide the keyboard
        [viewController.view endEditing:YES];
    }
}

//*******************

Upvotes: 1

Related Questions