在ios 7中使用twitter登录 [英] Login with twitter in ios 7

查看:256
本文介绍了在ios 7中使用twitter登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做登录功能。
其中 -

I am doing login functionality. In which -



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

  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.

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

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.

如果用户尚未从ios配置Twitter帐户设置然后,如果用户从我的应用程序登录屏幕点击Twitter登录按钮,它将
导航用户到用户必须提供
电子邮件ID(推特ID)和密码的推特页面,如果登录是成功的它
应该回到我的应用程序的内部屏幕(与Facebook登录
的功能相同)。

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.

推荐答案

首先,您无法使用iOS7框架或Twitter的Native从twitter的API获取用户电子邮件地址API。

如果您想获取用户电子邮件地址,可以要求用户手动输入。这就是Twitter人们在他们的API文档中所说的内容。对于你的Point 2和3,这里是使用iOS7方式的示例代码

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

这篇关于在ios 7中使用twitter登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆