8

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?

Amiram Stark
  • 2,208
  • 22
  • 32

4 Answers4

3

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.

Community
  • 1
  • 1
SpacyRicochet
  • 2,269
  • 2
  • 24
  • 39
  • Thanks for giving a full answer, even though it's "no, you can't really do that." I also think that redirecting people to a different solution for handling more complex tweeting is helpful. – Stephen Furlani Jun 28 '12 at 19:21
  • No problem and thanks for the award. But yeah, it would've been more fun to say "you can do this so-and-so" instead of "no, you can't". Hopefully this will help others too. – SpacyRicochet Jun 29 '12 at 11:14
1

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.

Saleh
  • 380
  • 3
  • 19
  • 1
    This could work, though it isn't a really safe method. You're never sure if iOS hasn't increased the number of window subviews on its own at any given moment. – SpacyRicochet Jun 27 '12 at 08:42
  • Yes, but you can check the subview just before sending the tweet and again when the TWTweetComposeViewControllerResultDone gets called. Apple adds the subviews only on start of the app. – Saleh Jun 27 '12 at 08:45
  • You're never sure of that, that's the problem. Apple suddenly might have something to say about battery life. Or about your internet connection failing. Perhaps the notifications count as subviews as well. And even worse, what happens when in a new iOS version they decide that alert dialogs aren't the current window's subviews anymore, but instead are a new window's subview? – SpacyRicochet Jun 27 '12 at 08:51
  • yes, i know this is not foolproof but it can work as a work around as we don't have any definitive method for this. – Saleh Jun 27 '12 at 08:57
-1
    [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....

GameLoading
  • 6,688
  • 2
  • 33
  • 57
-1

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.

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52