Login with twitter in ios 7

给你一囗甜甜゛ 提交于 2019-12-20 17:31:12

问题


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:


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.
}


来源:https://stackoverflow.com/questions/21202274/login-with-twitter-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!