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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With