【问题标题】:Is it possible to check if a user has a twitter account in the built-in twitter app of iOS 5?是否可以在 iOS 5 的内置 Twitter 应用程序中检查用户是否有 Twitter 帐户?
【发布时间】:2012-01-05 02:12:35
【问题描述】:

iOS 5 具有深度 Twitter 集成。如何检查用户是否在内置 twitter 应用程序中拥有帐户(意味着他使用它),然后执行 UIApplication openURL: 以触发关注用户或预先撰写推文?

iOS 5 SDK 中面向开发人员的新功能之一是支持 推特 API。 Apple 让开发者可以轻松添加 Twitter 支持他们的应用程序并允许用户轻松控制是否 没有一个应用可以访问他们的 Twitter 帐户。

根据this site 是可以的。那个 Twitter 框架叫什么名字?

【问题讨论】:

  • 为他辩护,他还询问是否启动 Twitter 应用程序,以便用户可以关注一个帐户。
  • @dontWatchMyProfile 实际上,我不知道答案。我什至不是 iOS 开发人员。如果我找到了,你也可以。这就是否决按钮的用途。

标签: iphone ios ipad twitter


【解决方案1】:

你可以试试这样的:

BOOL didOpenTwitterApp = [UIApplication openURL:[NSURL URLWithString:@"twitter:///user?screen_name=senior"]];

如果应用无法打开官方 Twitter 应用,这将返回 false。

如果你只想创建一条新推文,请使用native API

【讨论】:

    【解决方案2】:

    试试这个:

    - (void)tweetButtonPressed:(id)sender
    {
         Class tweetComposer = NSClassFromString(@"TWTweetComposeViewController");
    
         if( tweetComposer != nil ) {   
    
             if( [TWTweetComposeViewController canSendTweet] ) {
                TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
    
                [tweetViewController setInitialText:@"This is a test."];  // set your initial text
    
                tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
                    if( result == TWTweetComposeViewControllerResultDone ) 
                    {
                        // user is done with composing
                    } 
                    else if( result == TWTweetComposeViewControllerResultCancelled ) 
                    {
                        // user has cancelled composing
                    }
                    [self dismissViewControllerAnimated:YES completion:nil];
                };
    
                [self presentViewController:tweetViewController animated:YES completion:nil];
            } 
            else {
                 // The user has no account setup
            }
        }   
        else {
            // no Twitter integration
        }
    }
    

    【讨论】:

      【解决方案3】:

      对于您问题的第一部分...

      ACAccountStore *accountStore = [[[ACAccountStore alloc] init] autorelease];
      ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
      NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
      

      这就是我们在DETweetComposeViewController 中的做法。

      【讨论】:

      • 我用过你的 twitter 库,真的很酷。虽然我有几个问题想问。 1) 我们可以检索用户的网名吗? 2)我们可以实现登录、注销功能吗?
      • 1) 您可以使用 Apple 的 ACAccount 框架在 iOS 5 上检索用户的 Twitter 屏幕名称。请参阅我们的 DETweetAccountSelectorViewController 类。 2)您不能在程序上“注销”iOS 5 Twitter(从应用程序的角度来看,您并没有真正登录)。用户必须转到设置应用程序才能执行此操作。但是,如果您正在实施 iOS 4 风格的推文,您可以完全控制登录和注销。请参阅 OAuth 例程。
      猜你喜欢
      • 1970-01-01
      • 2013-12-11
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      相关资源
      最近更新 更多