2012-09-17 65 views
4

我想用在iOS 5 用戶的Twitter框架將選擇使用哪個帳戶共享,因此應用程序將分享他們使用選定的帳戶。TWRequest performRequestWithHandler沒有錯誤,但沒有發生

但whem份額傳遞到performRequestWithHandler沒有發生的的error回報null

我的代碼:

for (int i = 0; i < [_accountsArray count]; i++) { 
//searching for a selected account 
      if ([[[_accountsArray objectAtIndex:i] username] isEqualToString:[self getUserName]]) { 
       actualUser = [_accountsArray objectAtIndex:i]; 
       TWRequest *sendTweet = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] 
                  parameters:nil 
                 requestMethod:TWRequestMethodPOST]; 

       [sendTweet addMultiPartData:[text dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"]; 
       ACAccountStore *account = [[ACAccountStore alloc] init]; 

       [sendTweet setAccount:[account.accounts objectAtIndex:i]]; 
       NSLog(@"%@",sendTweet.account); 

       [sendTweet performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 

        NSLog(@"responseData: %@\n", responseData); 
        NSLog(@"urlResponse: %@\n", urlResponse); 
        NSLog(@"error: %@",error); 

       }]; 
      } 
     } 

任何人都可以幫我嗎?

謝謝

+0

這也開始發生在我身上。出於某種原因,在iPod touch iOS5上它可以正常工作,但在iPhone 4 iOS6上卻不行。檢查網址是否正確:'的https:// api.twitter.com/1.1 /狀態/ update_with_media.json'對'的https:// upload.twitter.com/1 /狀態/ update_with_media.json' – cleverbit

回答

1

在iOS中發送推文是非常容易的。昨晚我更新了我的應用程序,不再使用舊技術,而是使用新的SLComposeViewController技術。下面是我的應用程序中的一小段代碼,它允許用戶發送附帶圖片的推文。基本上完全相同的代碼可以用於發佈到Facebook。請嘗試使用此代碼。它也應該允許用戶選擇什麼解釋他們把從鳴叫(我也相信這個「​​默認帳戶」發送設置埋在某個地方的手機的設置)。

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { 
     SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 
     [mySLComposerSheet setInitialText:@"Sample Tweet Text"]; 

     //Add the image the user is working with 
     [mySLComposerSheet addImage:self.workingImage]; 

     //Add a URL if desired 
     //[mySLComposerSheet addURL:[NSURL URLWithString:@"http://google.com"]]; 

     //Pop up the post to the user so they can edit and submit 
     [self presentViewController:mySLComposerSheet animated:YES completion:nil]; 

     //Handle the event 
     [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) { 
      switch (result) { 
       case SLComposeViewControllerResultCancelled: 
        NSLog(@"Tweet Canceled"); 
       case SLComposeViewControllerResultDone: 
        NSLog(@"Tweet Done"); 
        break; 
       default: 
        break; 
      } 
     }]; 

    } else { 
     //Can't send tweets, show error 
     NSLog(@"User doesn't have twitter setup"); 
    } 
相關問題