Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong Twitter result after unsuccessful send attempt

Tags:

ios

twitter

ios5

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?

like image 893
Amiram Stark Avatar asked Nov 13 '11 12:11

Amiram Stark


2 Answers

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.

like image 181
SpacyRicochet Avatar answered Nov 15 '22 04:11

SpacyRicochet


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.

like image 39
Saleh Avatar answered Nov 15 '22 03:11

Saleh