OpenChatCreatingController

public class OpenChatCreatingController

A controller which manages open chat creating operations.

It checks whether the Open Chat user term has been accepted by current user. If accepted, LINE SDK shows a standard open chat creating interface to collect information from user input, then try to create the open chat room based on them. Otherwise, the user is prompted to agree the term first before an open chat room can be created.

It is encouraged to call OpenChatCreatingController.localAuthorizationStatusForCreatingOpenChat() first and check the authorization status to make sure your user has authorized you to create an open chat. Then call loadAndPresent(in:presentedHandler:) to show the built-in UI to collect user information and create the open chat room.

To get the result of the creating controller or have more control of the behaviors, implement methods in OpenChatCreatingControllerDelegate and set delegate property of an OpenChatCreatingController instance.

Note

The class is intended to be used as-is and to provide a default open chat creating experience across all LINE and LINE SDK integrations. Users expect a consistent UI and interaction across different apps when using the Open Chat features. But if it’s so important for you to provide a fully customized sharing interaction, you can still use the related APIs to create your own UIs.
  • The delegate object of this open chat creating controller.

    The delegate receives events when user encounters an error during open chat creating, user cancels the creating, or the creating finishes successfully. You can choose to implement one or more methods to offer your users a better experience when an event happens.

    For information about the methods you can implement for your delegate object, see OpenChatCreatingControllerDelegate.

    Declaration

    Swift

    public weak var delegate: OpenChatCreatingControllerDelegate?
  • The suggested category shows as the default category when user creates a new open chat room.

    Note

    Users can select a category in UI from a predefined list of OpenChatCategorys. It determines which category the created room should belong to. The suggestedCategory value will be show as the selected state when the user opens open chat creating UI.

    It does not prevent users from selecting another category from the list.

    Declaration

    Swift

    public var suggestedCategory: OpenChatCategory
  • Creates a OpenChatCreatingController with default behavior. Always use this initializer to create an OpenChatCreatingController instance.

    Declaration

    Swift

    public init()
  • Loads the user term agreement status and shows the open chat room UI if possible.

    Note

    If the handler is called with a .failure case, it means there is no view controller from LINE SDK shown. A few reasons can cause it, such as term agreement status cannot be retrieved due to network error. On the other hand, a .success case and its associated value means a view controller from LINE SDK is presented. But it does not mean that the open chat room is created. To handle either the creating failure or success case for the whole process, you need to use the methods in OpenChatCreatingControllerDelegate.

    For either result, it is a chance for you to remove any blocking UI you may add to your view controller, like this in your view controller:

    self.showLoadingIndicator()
    OpenChatCreatingController.loadAndPresent(in: self) { _ in
        self.hideLoadingIndicator()
    }
    

    Declaration

    Swift

    public func loadAndPresent(
        in viewController: UIViewController,
        presentedHandler handler: ((Result<UIViewController, LineSDKError>) -> Void)? = nil
    )

    Parameters

    viewController

    A presenting view controller from which the open chat creating view controller should be presented from. Normally, it should be your current top-most view controller which takes responsibility of user interaction.

    handler

    A block called when the open chat creating view controller presenting action is done with a result.

  • Gets the local authorization status for creating an open chat room.

    Note

    If the return value is .authorized, you can present a OpenChatCreatingController instance for creating a room. But .authorized status doesn’t necessarily mean the creating would succeed; there may be problems with the token or permissions.

    The token status is stored locally and may not have been synchronized with the server-side status. The token may have expired or been revoked by the server or via another client.

    To get the correct result about creating behavior, specify OpenChatCreatingController.delegate and implement the methods in OpenChatCreatingControllerDelegate.

    Declaration

    Swift

    public static func localAuthorizationStatusForCreatingOpenChat() -> AuthorizationStatus

    Return Value

    The local authorization status based on the currently stored token and the permissions specified in that token.