TWTweetComposeViewController Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Twitter.framework
Availability
Available in iOS 5.0 and later.
Deprecated in iOS 6.0.
Declared in
TWTweetComposeViewController.h

Overview

The TWTweetComposeViewController class presents a view to the user to compose a tweet.

Although you may perform Twitter requests on behalf of the user, you cannot append text, images, or URLs to tweets without the user’s knowledge. Hence, you can set the initial text and other content before presenting the tweet to the user but cannot change the tweet after the user views it. All of the methods used to set the content of the tweet return a Boolean value. The methods return NO if the content doesn’t fit in the tweet or if the view was already presented to the user and the tweet can no longer be changed.

Optionally, use the canSendTweet class method to check if Twitter is set up and reachable before presenting this view to the user.

You can also set a handler using the completionHandler property to be notified when the user is done composing the tweet. Note that completion handlers are not called on any particular thread.

Tasks

Checking Status

Composing Tweets

Handling Results

Properties

completionHandler

The handler to call when the user is done composing the tweet.

@property(nonatomic, copy) TWTweetComposeViewControllerCompletionHandler completionHandler
Discussion

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

Special Considerations

In iOS 6 and earlier, if you set a completion handler then your completion handler is responsible for dismissing the TWTweetComposeViewController using dismissViewControllerAnimated:completion:. In iOS 7 and later, you must not dismiss the TWTweetComposeViewController in your completion handler.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

Class Methods

canSendTweet

Returns whether you can send a Twitter request.

+ (BOOL)canSendTweet
Return Value

YES if Twitter is accessible and at least one account is set up; otherwise NO.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

Instance Methods

addImage:

Adds an image to the tweet.

- (BOOL)addImage:(UIImage *)image
Parameters
image

The image to add to the tweet.

Return Value

YES if successful. NO if image does not fit in the currently available character space or the view was presented to the user.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

addURL:

Adds a URL to the tweet.

- (BOOL)addURL:(NSURL *)url
Parameters
url

The URL to add to the tweet.

Return Value

YES if successful. NO if url does not fit in the currently available character space or the view was presented to the user.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

removeAllImages

Removes all images from the tweet.

- (BOOL)removeAllImages
Return Value

YES if successful. NO if the images were not removed because the view was presented to the user.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

removeAllURLs

Removes all URLs from the tweet.

- (BOOL)removeAllURLs
Return Value

YES if successful. NO if the URLs were not removed because the view was presented to the user.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

setInitialText:

Sets the initial text for a tweet.

- (BOOL)setInitialText:(NSString *)text
Parameters
text

The text to add to the tweet.

Return Value

YES if successful. NO if text does not fit in the currently available character space or the view was presented to the user.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

Constants

TWTweetComposeViewControllerCompletionHandler

Defines a handler to call when the user finishes composing the tweet.

typedef void (^TWTweetComposeViewControllerCompletionHandler)(TWTweetComposeViewControllerResult result);
Discussion

See “TWTweetComposeViewControllerResult” for possible values of the result parameter. Use the completionHandler property to set this handler.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h

TWTweetComposeViewControllerResult

Possible values for the result parameter of the completionHandler property.

enum TWTweetComposeViewControllerResult {
   TWTweetComposeViewControllerResultCancelled,
   TWTweetComposeViewControllerResultDone
};
typedef enum TWTweetComposeViewControllerResult TWTweetComposeViewControllerResult;
Constants
TWTweetComposeViewControllerResultCancelled

The user cancelled composing a tweet.

Available in iOS 5.0 and later.

Declared in TWTweetComposeViewController.h.

TWTweetComposeViewControllerResultDone

The user finished composing a tweet.

Available in iOS 5.0 and later.

Declared in TWTweetComposeViewController.h.

Availability
  • Available in iOS 5.0 and later.
Declared In
TWTweetComposeViewController.h