2012-04-04 128 views
1

我想从iOS 5中的应用程序中打开Twitter应用程序,但它不会打开。任何帮助将不胜感激,我已经包括我在下面使用的代码。从我的iOS 5应用程序打开Twitter应用程序

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]]; 

请帮助我,并提前致谢!

回答

0

你想推出Twitter应用程序,还是只发送你的应用程序内的推文?我相信您上面显示的代码是在您的设置应用中启动Twitters偏好设置......我也相信已被禁止使用5.1

如果您希望将Twitter集成添加到您的应用中Apple提供了很好的示例代码向你展示如何在iOS 5中使用推特内置的Twitter框架使用Twitter。

现在我建议你下载这个示例代码,看看还有什么需要发送推文(如检查CanTweetStatus),但我附加如何在这篇文章中发送推文的基本思路。

https://developer.apple.com/library/ios/#samplecode/Tweeting/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011191

- (IBAction)sendCustomTweet:(id)sender { 
    // Create an account store object. 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    // Create an account type that ensures Twitter accounts are retrieved. 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    // Request access from the user to use their Twitter accounts. 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if(granted) { 
      // Get the list of Twitter accounts. 
      NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 

      // For the sake of brevity, we'll assume there is only one Twitter account present. 
      // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present. 
      if ([accountsArray count] > 0) { 
       // Grab the initial Twitter account to tweet from. 
       ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 

       // Create a request, which in this example, posts a tweet to the user's timeline. 
       // This example uses version 1 of the Twitter API. 
       // This may need to be changed to whichever version is currently appropriate. 
       TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST]; 

       // Set the account used to post the tweet. 
       [postRequest setAccount:twitterAccount]; 

       // Perform the request created above and create a handler block to handle the response. 
       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
        [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; 
       }]; 
      } 
     } 
    }]; 
} 

祝您好运!

4

如果你只是试图打开实际的Twitter的应用程序,然后将代码

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://"]]; 
+0

它打开Twitter的应用程序不是Twitter的设置。 – PJR 2012-07-04 08:20:32

+0

不允许从应用程序打开偏好设置 – Otium 2012-07-04 21:02:25