2013-01-07 21 views
2

我想直接從我的iPhone應用程序發出信息,而不顯示TWTweetComposeViewController彈出發送資料Tweet沒有TWTweetComposeViewController

此外,我想所有的追隨者 是有辦法做到這一點從Twitter框架上的iOS5或應我使用另一個API!

如果我必須使用另一個API可以指定一個偉大的API爲我?因爲我在互聯網上發現的所有頂點 都很舊。

在此先感謝

回答

3

如果您使用的是iOS 5.0或更高版本,則可以使用TWRequest以編程方式發佈來自我的應用程序的推文。發佈推文非常簡單,不需要外部框架或任何東西。您需要#import <Twitter/Twitter.h>。您從iPhone帳戶存儲中檢索Twitter帳戶(您可以檢查是否有多個帳戶),然後使用該帳戶發佈請求。

下面是一個用圖像發佈推文的方法示例。

- (void)shareTwitterImage:(UIImage *)image 
{ 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) 
    { 
     if(granted) 
     { 
      NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 

      if ([accountsArray count] > 0) 
      { 
       ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 

       TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:[NSDictionary dictionaryWithObject:self.textViewOutlet.text forKey:@"status"] requestMethod:TWRequestMethodPOST]; 

       [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"]; 
       [postRequest setAccount:twitterAccount]; 

       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
        { 
         //show status after done 
         NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
         NSLog(@"Twiter post status : %@", output); 
        }]; 
      } 
     } 
    }]; 
} 
1

有相當多的選擇:

好了,在iOS 6,還有就是蘋果Social框架,你可以使用SLComposeViewController張貼到Twitter以及Facebook和新浪網微博,這裏是docsTWTweetComposeViewController已被棄用,運行iOS 6的設備將不得不運行到後向兼容性 - 所以要避免這種情況。

也有ShareKit,但我通常不推薦它,它的雜亂和臃腫。最後有Oauth Library in iOS ...創建一個消費者密鑰和密鑰。 You can also call the Twitter API with TWRequest

這些都是我能想到的。

羅漢。