LoginManager

public final class LoginManager : @unchecked Sendable

Represents a login manager. You can set up the LINE SDK configuration, log in and log out the user with the LINE authorization flow, and check the authorization status.

  • The shared instance of the login manager. Always use this instance to interact with the login process of the LINE SDK.

    Declaration

    Swift

    public static let shared: LoginManager
  • The current login process. A non-nil value indicates that there is an ongoing process and the LINE SDK is waiting for the login result; nil otherwise.

    Declaration

    Swift

    public private(set) var currentProcess: LoginProcess? { get }
  • Checks and returns whether the current LoginManager instance is ready to use. Call the setup method to set up the LINE SDK with basic information before you call any other methods or properties in the LINE SDK.

    Declaration

    Swift

    public var isSetupFinished: Bool { get }
  • Checks and returns whether the user was authorized and an access token exists locally. This method does not check whether the access token has been expired. To verify an access token, use the API.Auth.verifyAccessToken method.

    Declaration

    Swift

    public var isAuthorized: Bool { get }
  • Checks and returns whether the authorizing process is currently ongoing.

    Declaration

    Swift

    public var isAuthorizing: Bool { get }
  • Sets up the current LoginManager instance.

    Note

    Call this method before you access any other methods or properties in the LINE SDK. Call this method only once because the login manager cannot be set up multiple times.

    We strongly suggest that you specify a valid universal link URL. Set up your own universal link callback for your channel by following the guide on the LINE Developers site. When the callback is set properly, LINE will try to bring up your app with the universal link first, which improves the security of the authorization flow and protects your data. If the universalLinkURL parameter is nil, only a custom URL scheme will be used to open your app after the authorization in LINE is complete.

    Declaration

    Swift

    public func setup(channelID: String, universalLinkURL: URL?)

    Parameters

    channelID

    The channel ID for your app.

    universalLinkURL

    The universal link used to navigate back to your app from LINE.

  • Resets the LINE SDK to its initial state.

    This method clears all SDK configurations, shared instances, and cancels any ongoing login process. After calling this method, you must call setup(channelID:universalLinkURL:) again before using any other SDK functionality.

    Important

    Access tokens remain stored in the keychain and are scoped by channel ID. Resetting with the same channel reuses the existing token. Call logout() before reset() if you need to remove cached credentials.

    Warning

    If there is an ongoing login process when this method is called, the login completion handler will be invoked with a LineSDKError.generalError(reason: .loginManagerReset) error.

    Note

    This method is @MainActor isolated. Call it on the main thread to ensure the login process cancellation is delivered immediately.

    Usage Example

    // Reset the SDK to switch to a different channel
    LoginManager.shared.reset()
    LoginManager.shared.setup(channelID: "newChannelID", universalLinkURL: nil)
    

    Declaration

    Swift

    @MainActor
    public func reset()
  • Logs in to the LINE Platform.

    Note

    Only one process can be started at a time. Do not call this method again to start a new login process before completion is invoked.

    If the value of permissions contains .profile, the user profile will be retrieved during the login process and contained in the userProfile property of the LoginResult object in completion. Otherwise, the userProfile property will be nil. Use this profile to identify your user. For more information, see UserProfile.

    An access token will be issued if the user authorizes your app. This token and a refresh token will be automatically stored in the keychain of your app for later use. You do not need to refresh the access token manually because any API call will attempt to refresh the access token if necessary. However, if you need to refresh the access token manually, use the API.Auth.refreshAccessToken(with:) method.

    Declaration

    Swift

    @discardableResult
    @MainActor
    public func login(
        permissions: Set<LoginPermission> = [.profile],
        in viewController: UIViewController? = nil,
        parameters: LoginManager.Parameters = .init(),
        completionHandler completion: @escaping (Result<LoginResult, LineSDKError>) -> Void
    ) -> LoginProcess?

    Parameters

    permissions

    The set of permissions requested by your app. The default value is [.profile].

    viewController

    The the view controller that presents the login view controller. If nil, the topmost view controller in the current view controller hierarchy will be used.

    parameters

    The parameters used during the login process. For more information, see LoginManager.Parameters.

    completion

    The completion closure to be invoked when the login action is finished.

    Return Value

    The LoginProcess object which indicates that this method has started the login process.

  • Logs out the current user by revoking the refresh token and all its corresponding access tokens.

    Declaration

    Swift

    public func logout(completionHandler completion: @escaping @Sendable (Result<(), LineSDKError>) -> Void)

    Parameters

    completion

    The completion closure to be invoked when the logout action is finished.

  • Logs out the current user by revoking the refresh token and all its corresponding access tokens.

    Declaration

    Swift

    public func logout() async throws
  • Asks this LoginManager object to handle a URL callback from either LINE or the web login flow.

    Note

    This method has the same method signature as in the methods of the UIApplicationDelegate protocol. Pass all arguments to this method without any modification.

    Declaration

    Swift

    @MainActor
    public func application(
        _ app: UIApplication,
        open url: URL?,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

    Parameters

    app

    The singleton app object.

    url

    The URL resource to open. This resource should be the one passed from the iOS system through the related method of the UIApplicationDelegate protocol.

    options

    A dictionary of the URL handling options passed from the related method of the UIApplicationDelegate protocol.

    Return Value

    true if url has been successfully handled; false otherwise.

  • A non-isolated version of the application(_:open:options:) method. This is temporarily for Flutter SDK use only, as the Flutter SDK is not marking @MainActor in the FlutterApplicationLifeCycleDelegate.

    Warning

    Prefer using the isolated application(_:open:options:) version whenever possible.

    Declaration

    Swift

    public func nonisolatedApplication(
        _ app: UIApplication,
        open url: URL?,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
  • Sets the preferred language used when logging in with the web authorization flow.

    If not set, the web authentication flow shows the login page in the user’s device language, or falls back to English. Once set, the web page will be displayed in the preferred language.

    Note

    This property does not affect the preferred language when LINE is used for authorization. LINE and the login screen are always displayed in the user’s device language.

    Declaration

    Swift

    @available(*, deprecated, message: "Set the preferred language in a `LoginManager.Parameters` value and use\n`login(permissions:in:parameters:completionHandler:﹚` instead.\"﹚")
    public var preferredWebPageLanguage: WebPageLanguage?
  • Logs in to the LINE Platform.

    Note

    Only one process can be started at a time. Do not call this method again to start a new login process before completion is invoked.

    If the value of permissions is .profile, the user profile will be retrieved during the login process and contained in the userProfile property of the LoginResult object in completion. Otherwise, the userProfile property will be nil. Use this profile to identify your user. For more information, see UserProfile.

    An access token will be issued if the user authorizes your app. This token and a refresh token will be automatically stored in the keychain of your app for later use. You do not need to refresh the access token manually because any API call will attempt to refresh the access token if necessary. However, if you need to refresh the access token manually, use the API.Auth.refreshAccessToken(with:) method.

    Declaration

    Swift

    @available(*, deprecated, message: "Convert the `options` to a `LoginManager.Parameters` value and\nuse `login(permissions:in:parameters:completionHandler:﹚` instead.\"﹚")
    @discardableResult
    @MainActor
    public func login(
        permissions: Set<LoginPermission> = [.profile],
        in viewController: UIViewController? = nil,
        options: LoginManagerOptions,
        completionHandler completion: @escaping (Result<LoginResult, LineSDKError>) -> Void) -> LoginProcess?

    Parameters

    permissions

    The set of permissions requested by your app. The default value is [.profile].

    viewController

    The the view controller that presents the login view controller. If nil, the topmost view controller in the current view controller hierarchy will be used.

    options

    The options used during the login process. For more information, see LoginManagerOptions.

    completion

    The completion closure to be invoked when the login action is finished.

    Return Value

    The LoginProcess object which indicates that this method has started the login process.

  • Parameters used during login.

    See more

    Declaration

    Swift

    public struct Parameters : Sendable
  • The style for showing the “Add LINE Official Account as friend” prompt on the consent screen.

    See more

    Declaration

    Swift

    public enum BotPrompt : String, Sendable
  • The method used for the authentication when using the web authentication flow.

    Declaration

    Swift

    public enum WebAuthenticationMethod : String, Sendable
  • Represents the language used in the web page.

    See more

    Declaration

    Swift

    public struct WebPageLanguage : Sendable