是否有可能检查用户是否有iOS 5的内置twitter应用程序的Twitter帐户?

iOS 5具有深入的Twitter整合。 我如何检查用户是否在内置的twitter应用程序(意思是他使用它)中有一个帐户,然后做一个UIApplication openURL:触发跟随一个用户或预先撰写推文?

iOS 5 SDK中的开发人员的新function之一是支持Twitter API。 苹果已经使开发者能够轻松地将Twitter支持添加到他们的应用程序,并允许用户轻松控制应用程序是否有权访问他们的Twitter帐户。

根据这个网站是可能的。 那个Twitter框架怎么叫?

尝试这个:

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

对于你的问题的第一部分…

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

这是我们如何在DETweetComposeViewController中做的。

你可以尝试像这样:

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

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

如果您只想创build新的Tweet,请使用本地API