2012-04-04 3 views
1

Я пытаюсь открыть приложение Twitter из своего приложения в iOS 5, но оно не открывается. Любая помощь будет оценена, я включил код, который я использую ниже.Открыть приложение Twitter из моего приложения iOS 5

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

Пожалуйста, помогите мне, и спасибо заранее!

ответ

0

Вы хотите запустить приложение Twitter или просто отправить твиты из своего приложения? Я считаю, что код, который вы показываете выше, - это настроить параметры запуска Twitters в вашем приложении настроек ... Я также считаю, что это запрещено в 5.1.

Если вы хотите добавить интеграцию Twitter в свое приложение, Apple предоставляет отличный образец кода чтобы показать вам, как использовать Twitter со встроенными фреймворками Twitter в iOS 5.

Теперь я рекомендую вам скачать этот пример кода и посмотреть, что еще требуется для отправки твита (например, проверка 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]; 
       }]; 
      } 
     } 
    }]; 
} 

Good Luck!

4

Если вы просто пытаетесь открыть реальное приложение Twitter, то код

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

это открытие твиттер приложения не щебет Настройки. – PJR

+0

Невозможно открыть настройки из приложений – Otium

Смежные вопросы