是否可以检查用户是否在iOS 5的内置Twitter应用程序中拥有Twitter帐户?

don*_*ile 1 iphone twitter ipad ios

iOS 5具有深度的Twitter集成.如何检查用户是否在内置的Twitter应用程序中拥有一个帐户(意味着他使用了该应用程序),然后执行a操作UIApplication openURL:来触发用户或预先编写推文?

iOS 5 SDK中开发人员的新功能之一是支持Twitter API.Apple使开发人员可以轻松地将Twitter支持添加到他们的应用程序中,并允许用户轻松控制应用程序是否可以访问其Twitter帐户.

根据这个网站,这是可能的.Twitter框架如何调用?

qua*_*tym 12

试试这个:

- (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
    }
}
Run Code Online (Sandbox Code Playgroud)