Login with twitter in ios 7

6k Views Asked by At

I am doing login functionality. In which -

  1. user will give twitter email id to login and if login gets succeeded, my app will navigate user to its inner screen of my app.

  2. If user has configured twitter account from user's device ios settings. My app takes user's email id from there and it will navigate into second screen of my app.

  3. If user has not configured twitter account from ios settings then, if user tapps a button login with twitter from my app login screen, it will navigate user to the twitter page from where user has to give email id (twitter id) and password and if login is successful it should back to my app's inner screen(same functionality as like login with facebook).

how could I achieve this. Thanks in advance.

1

There are 1 best solutions below

1
On

First of all, you can not get user email address from twitter's API either using iOS7 framework or Twitter's Native API.
If you want to get user email address you can ask user to enter it manually. That's what Twitter people say in their API Docs. For your Point 2 and 3 here is the sample code using iOS7 way

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
{
    self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore

    ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
     {
         if (granted)
         {
             self.twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
             NSLog(@"Twitter UserName: %@, FullName: %@", self.twitterAccount.username, self.twitterAccount.userFullName);
             [self getTwitterEmail]; // here you can ask user to enter email address. Its up to you how you ask user about it. Either in alert View or in Text Field.
         }
         else
         {
             if (error == nil) {
                 NSLog(@"User Has disabled your app from settings...");
             }
             else
             {
                 NSLog(@"Error in Login: %@", error);
             }
         }
     }];
}
else
{
    NSLog(@"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
}