سؤال

I'm trying to share using Twitter Framework on iOS 5 The user will select which account to use, so the app will share using the account selected.

But whem share pass to performRequestWithHandler nothing happen an the error return null

My code:

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);

                }];
            }
        }

anyone can help me?

Thanks

هل كانت مفيدة؟

المحلول

Sending tweets in iOS is extremely easy now. Last night I updated my app to no longer use the old technique and instead use the new SLComposeViewController technique. Below is a snippet of code I have in my application that allows the user send a tweet with the attached image. Basically the exact same code can be used to post to facebook. Try using this code instead. It should also allow the user to choose what account they send the tweet from (I also believe this "default account" sending setting is buried in the settings of the phone someplace).

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");
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top