Is it possible to check if a user has a twitter ac

2019-04-02 14:45发布

iOS 5 has deep twitter integration. How can I check if the user has an account in the built-in twitter app (meaning he uses it), and then do a UIApplication openURL: to trigger following a user or pre-composing a tweet?

One of the new features for developers in the iOS 5 SDK is support for the Twitter API. Apple has made it easy for developers to add Twitter support to their apps and to allow users to easily control whether or not an app has access to post to their Twitter account.

According to this site it is possible. How's that Twitter Framework called?

3条回答
该账号已被封号
2楼-- · 2019-04-02 15:16

Try this:

- (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楼-- · 2019-04-02 15:16

For the first part of your question...

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

This is how we're doing it in DETweetComposeViewController.

查看更多
混吃等死
4楼-- · 2019-04-02 15:31

You could try something like:

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

This will return false if the app can't open the official Twitter app.

If you just want to create a new Tweet, use the native API

查看更多
登录 后发表回答