iOS Developer Library — Pre-Release

Developer

Social Framework Reference SLComposeViewController Class Reference

Options
Deployment Target:

On This Page
Language:

SLComposeViewController

Inheritance


Conforms To


Import Statement


Swift

import Social

Objective-C

@import Social;

Availability


Available in iOS 6.0 and later.

The SLComposeViewController class presents a view to the user to compose a post for supported social networking services.

Use the isAvailableForServiceType: class method to check if a service account, such as Twitter, is set up and reachable before presenting this view to the user.

Set the initial content before presenting the view controller to the user. All the methods that set the content of a post return a Boolean value. They return NOfalse if the content doesn’t fit in the post or if the view controller has already been presented to the user. You must set all of the content in the post before presenting the view controller to the user. After presenting the view controller, only the user can edit the post.

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

  • Creates a new social compose view controller.

    Declaration

    Swift

    init!(forServiceType serviceType: String!) -> SLComposeViewController

    Objective-C

    + (SLComposeViewController *)composeViewControllerForServiceType:(NSString *)serviceType

    Parameters

    serviceType

    This specifies the social networking service you want to post to. You must use one of the possible values listed in Service Type Constants. This also sets the value of serviceType. If an invalid serviceType is passed in, this method throws an exception.

    Return Value

    Returns a social compose view controller or nil if an error occurs.

    Discussion

    Use this method to create a social compose view controller. Do not use any other methods.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Returns whether you can send a request for a particular service type.

    Declaration

    Swift

    class func isAvailableForServiceType(_ serviceType: String!) -> Bool

    Objective-C

    + (BOOL)isAvailableForServiceType:(NSString *)serviceType

    Parameters

    serviceType

    The social networking service. For a list of possible values, see Service Type Constants.

    Return Value

    Returns a Boolean value indicating whether the service is accessible and at least one account is set up.

    Discussion

    For the account to be available, the user must be logged into the social service in the device settings.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Specifies the social networking service.

    Declaration

    Swift

    var serviceType: String! { get }

    Objective-C

    @property(nonatomic, readonly) NSString *serviceType

    Discussion

    The value of this property is set when you initialize a social compose view controller in composeViewControllerForServiceType:. Each social view controller you present is connected to only one social service at a time. Use this property to check which service your social view controller has specified. For a list of possible values, see Service Type Constants.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Sets the initial text to be posted.

    Declaration

    Swift

    func setInitialText(_ text: String!) -> Bool

    Objective-C

    - (BOOL)setInitialText:(NSString *)text

    Parameters

    text

    The text to add to the post.

    Return Value

    Returns a Boolean value indicating whether the text was successfully set.

    Discussion

    This method returns NOfalse if text does not fit in the currently available character space or if the view controller has already been presented to the user (and therefore cannot be changed). Character limits are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1 Social Services Individual Documentation Sites.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Adds an image to the post.

    Declaration

    Swift

    func addImage(_ image: UIImage!) -> Bool

    Objective-C

    - (BOOL)addImage:(UIImage *)image

    Parameters

    image

    The image to add to the post.

    Return Value

    Returns a Boolean value indicating whether the image was successfully added.

    Discussion

    This method returns NOfalse if image does not fit in the currently available space or if the view controller has already been presented to the user (and therefore cannot be changed). For the accepted UIImage formats, see Supported Image Formats. Image size limits are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1 Social Services Individual Documentation Sites.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Removes all images from the post.

    Declaration

    Swift

    func removeAllImages() -> Bool

    Objective-C

    - (BOOL)removeAllImages

    Return Value

    Returns a Boolean value indicating whether the images were successfully removed.

    Discussion

    If the view controller has already been presented to the user when removeAllImages is called, the method returns NOfalse and the images are not removed.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Adds a URL to the post.

    Declaration

    Swift

    func addURL(_ url: NSURL!) -> Bool

    Objective-C

    - (BOOL)addURL:(NSURL *)url

    Parameters

    url

    The URL to add to the post.

    Return Value

    Returns a Boolean value indicating whether the URL was successfully added.

    Discussion

    This method returns NOfalse if url does not fit in the currently available character space or if the view controller has already been presented to the user (and therefore cannot be changed). Character limits are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1 Social Services Individual Documentation Sites.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

  • Removes all URLs from the post.

    Declaration

    Swift

    func removeAllURLs() -> Bool

    Objective-C

    - (BOOL)removeAllURLs

    Return Value

    Returns a Boolean value indicating whether the URLs were successfully removed.

    Discussion

    If the view controller has already been presented to the user when removeAllURLs is called, the method returns NOfalse and the URLS are not removed.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    var completionHandler: SLComposeViewControllerCompletionHandler!

    Objective-C

    @property(nonatomic, copy) SLComposeViewControllerCompletionHandler completionHandler

    Discussion

    The handler has a single parameter that indicates whether the user finished or cancelled composing the post. This block is not guaranteed to be called on any particular thread.

    Special Considerations

    In iOS 6 and earlier, if you set a completion handler then your completion handler is responsible for dismissing the SLComposeViewController using dismissViewControllerAnimated:completion:. In iOS 7 and later when compiled with the iOS 7 or later SDK you must not dismiss the SLComposeViewController in your completion handler—the system will do so automatically.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

Data Types

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

    Declaration

    Swift

    typealias SLComposeViewControllerCompletionHandler = (SLComposeViewControllerResult) -> Void

    Objective-C

    typedef void (^SLComposeViewControllerCompletionHandler) (SLComposeViewControllerResult result);

    Discussion

    The completion handler is called while the SLComposeViewController is still visible and it is responsible for dismissing the view controller. For the possible values of the result parameter, see SLComposeViewControllerResult. Use the completionHandler property to set this handler.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    enum SLComposeViewControllerResult : Int { case Cancelled case Done }

    Objective-C

    typedef NS_ENUM (NSInteger, SLComposeViewControllerResult ) { SLComposeViewControllerResultCancelled, SLComposeViewControllerResultDone };

    Constants

    • Cancelled

      SLComposeViewControllerResultCancelled

      The view controller is dismissed without sending the post. For example, the user selects Cancel or the account is not available.

      Available in iOS 6.0 and later.

    • Done

      SLComposeViewControllerResultDone

      The view controller is dismissed and the message is being sent in the background. This occurs when the user selects Done.

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import Social;

    Swift

    import Social

    Availability

    Available in iOS 6.0 and later.