2014-01-18 79 views
1

我在做登录功能。 在其中 -使用twitter登录ios 7

  1. 用户将给Twitter的电子邮件ID登录,如果登录成功得到,我的应用程序将用户导航到我的应用程序的其内部的屏幕。

  2. 如果用户从用户的设备ios设置配置了Twitter帐户。我的应用程序会从那里获取用户的电子邮件ID,它会将 导航到我的应用程序的第二个屏幕。

  3. 如果用户未从IOS配置的Twitter帐户,然后设置,如果用户从我的应用程序登录屏幕tapps按钮登录与Twitter,它 将导航用户从那里用户拥有Twitter页面给予 电子邮件ID(推特ID)和密码,如果登录成功,它应该回到我的应用程序的内屏幕(相同的功能,如登录 与脸书)。

我怎么能做到这一点。提前致谢。

+0

你有没有做过这方面的事情? – DAMM108

+0

@ DAMMM108:谢谢你的回复我已经通过使用旧的Twitter的API,但我想从iOS标准库做到这一点。可能吗?谢谢 –

+0

没有这不可能从ios标准框架,而是使用https://github.com/nst/STTwitter,它是一个好的 – DAMM108

回答

5

首先,您无法使用iOS7框架或Twitter的Native API从Twitter的API获取用户电子邮件地址。
如果你想获得用户的电子邮件地址,你可以要求用户手动输入。这就是Twitter人在他们的API文档中所说的。对于你的第2点和第3点,这里是使用iOS7的示例代码

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

'userFullName'现在只适用于'Facebook'。 – Hemang