2014-01-18 74 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