【问题标题】:iOS Twitter IntegrationiOS 推特集成
【发布时间】:2014-02-06 08:46:50
【问题描述】:

我想将 twitter 集成到我的应用程序中,主要用于登录目的,我想像下面的案例一样实现它

  1. 检查是否有任何 Twitter 帐户已与手机使用反向身份验证相关联
  2. 如果没有关联帐户,请使用一些用于 twitter 的 OAuth 库并使用该库进行身份验证

任何人都知道任何现有的库/框架做同样的事情吗?谢谢

P.S : 支持的最低 iOS 版本为 iOS6

【问题讨论】:

    标签: ios twitter twitter-oauth


    【解决方案1】:

    您可以使用以下代码:(如果在设置中没有找到帐户,那么这会将您的应用程序带到设备的设置屏幕):

    - (IBAction)loginWithTwitterBtn:(id)sender
    {
        if ([TWTweetComposeViewController canSendTweet])
        {
            //yes user is logged in
            accountStore = [[ACAccountStore alloc] init];
            ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    
            // Request access from the user to use their Twitter accounts.
            [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
             {
                 // Did user allow us access?
                 if (granted == YES)
                 {
                     // Populate array with all available Twitter accounts
                     NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
    
                     ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
    
                     // Set the cell text to the username of the twitter account
                     NSString *userID = [[acct valueForKey:@"properties"] valueForKey:@"user_id"];
    
                 }
             }];
        }
        else
        {
            //show tweeet login prompt to user to login
            TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
    
            //hide the tweet screen
            viewController.view.hidden = YES;
    
            //fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
            viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
                if (result == TWTweetComposeViewControllerResultCancelled) {
                    [self dismissModalViewControllerAnimated:NO];
                }
            };
            [self presentModalViewController:viewController animated:NO];
    
            //hide the keyboard
            [viewController.view endEditing:YES];
        }
    }
    
    //*******************
    

    【讨论】:

    • 现在检查,谢谢!
    • 它给出了很多不推荐使用的警告,并且在没有配置帐户时不显示登录提示!
    • 实际上我已经在 iOS 6 中实现了它。当我在答案顶部添加注释时,如果它没有找到任何 twitter 帐户,它会显示提醒用户进入设置屏幕..跨度>
    • 我想在iOS 6 + iOS 7中实现
    【解决方案2】:

    https://github.com/aryansbtloe/LoginViaSocialMedias

    这是一个示例项目,用于向您的 ios 应用程序添加通过 facebook、twitter、google plus 和四方支持登录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-17
      • 2012-06-01
      • 2020-05-29
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      相关资源
      最近更新 更多