iOS Developer Library

Developer

Twitter Framework Reference TWTweetComposeViewController Class Reference

Options
Deployment Target:

On This Page
Language:

TWTweetComposeViewController

Inherits From


Import Statement


Swift

import Twitter

Objective-C

@import Twitter;

Availability


Available in iOS 5.0 and later
Deprecated in iOS 6.0

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 NOfalse 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.

  • Returns whether you can send a Twitter request.

    Declaration

    Objective-C

    + (BOOL)canSendTweet

    Return Value

    YEStrue if Twitter is accessible and at least one account is set up; otherwise NOfalse.

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

  • Sets the initial text for a tweet.

    Declaration

    Objective-C

    - (BOOL)setInitialText:(NSString *)text

    Parameters

    text

    The text to add to the tweet.

    Return Value

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

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

  • Adds an image to the tweet.

    Declaration

    Objective-C

    - (BOOL)addImage:(UIImage *)image

    Parameters

    image

    The image to add to the tweet.

    Return Value

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

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

  • addURL: - addURL: (iOS 6.0)

    Adds a URL to the tweet.

    Declaration

    Objective-C

    - (BOOL)addURL:(NSURL *)url

    Parameters

    url

    The URL to add to the tweet.

    Return Value

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

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

  • Removes all images from the tweet.

    Declaration

    Objective-C

    - (BOOL)removeAllImages

    Return Value

    YEStrue if successful. NOfalse if the images were not removed because the view was presented to the user.

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

  • Removes all URLs from the tweet.

    Declaration

    Objective-C

    - (BOOL)removeAllURLs

    Return Value

    YEStrue if successful. NOfalse if the URLs were not removed because the view was presented to the user.

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

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

    Declaration

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import Twitter;

    Availability

    Available in iOS 5.0 and later

    Deprecated in iOS 6.0

Data Types

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

    Declaration

    Swift

    typealias TWTweetComposeViewControllerCompletionHandler = SLComposeViewControllerCompletionHandler

    Objective-C

    typedef void (^TWTweetComposeViewControllerCompletionHandler)(TWTweetComposeViewControllerResult result);

    Discussion

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

    Import Statement

    Objective-C

    @import Twitter;

    Swift

    import Twitter

    Availability

    Available in iOS 5.0 and later

  • Possible values for the result parameter of the completionHandler property.

    Declaration

    Swift

    typealias TWTweetComposeViewControllerResult = SLComposeViewControllerResult

    Objective-C

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

    Constants

    • TWTweetComposeViewControllerResultCancelled

      TWTweetComposeViewControllerResultCancelled

      The user cancelled composing a tweet.

      Available in iOS 5.0 and later

    • TWTweetComposeViewControllerResultDone

      TWTweetComposeViewControllerResultDone

      The user finished composing a tweet.

      Available in iOS 5.0 and later

    Import Statement

    Objective-C

    @import Twitter;

    Swift

    import Twitter

    Availability

    Available in iOS 5.0 and later