Amiram Stark
Amiram Stark

Reputation: 2208

Wrong Twitter result after unsuccessful send attempt

When using TWTweetComposeViewController in IOS5 to compose and send a Tweet, if the Tweet is a duplicate, an error alert is shown saying that the Tweet is duplicate and cannot be sent, but the TWTweetComposeViewControllerCompletionHandler still gets a result value of TWTweetComposeViewControllerResultDone rather than TWTweetComposeViewControllerResultCancelled.

(This may happen in other cases as well, not just for duplicate tweets - I didn't check).

This makes it impossible to show a confirmation message to the user after a successful send, because the handler gets the same "Done" result whether the send was successful or not.

Is there another way to check whether the send was actually successful?

Upvotes: 8

Views: 773

Answers (4)

GameLoading
GameLoading

Reputation: 6708

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

                         if([urlResponse statusCode]==200)
                             {
//Tweet tweeted successfully....
    }
    }

this might help you . In respponse if url response code is 200 you can say text is tweeted....

Upvotes: -1

SpacyRicochet
SpacyRicochet

Reputation: 2279

The documentation for TWTweetComposeViewController's completionHandler states the following:

The handler has a single parameter that indicates whether the user finished or cancelled composing the tweet.

The completionhandler tells you whether the user actually finished or cancelled composing the tweet herself, regardless of the result of actually posting the tweet.

Update

I've looked a bit further into this and it seems like the TWTweetComposeViewController is one of those convenience classes that take away most of the work for the developer in exchange for not letting the developer handle anything by himself. In this case, the developer has no way of handling the errors that occur when sending the tweet and has to rely on the iOS provided alert dialogs to inform the user instead.

You can hack around this by using Saleh's method, though I don't consider that safe enough to use in an actual app. See the comments in his answer.

Another method is by implementing your own view controller which handles tweet composition and sending. You can do this by following the procedure in the following stackoverflow answer.

Upvotes: 3

Saleh
Saleh

Reputation: 380

Check for the alert message, if the alert message is shown you'll be able to know that the error occurred. I think that the alert message gets added in the window. You can check the count of window's subviews, if they get increased when delegate function is called, you'll know that the error occurred.

Upvotes: 1

Antwan van Houdt
Antwan van Houdt

Reputation: 6991

Isn't it only a view controller? The result of the view controller is fine as it states what happened with the view controller ( it is done running ).

With what are you sending your tweet? That library most likely has some stuff implemented you can use to determine whether your tweet was sent successfully or not.

Upvotes: -1

Related Questions