Integrate LINE Login with your iOS app

This guide explains how to implement LINE Login by integrating the LINE SDK for iOS with your existing iOS app. If you don’t have an existing app and would like to see what LINE Login can do, go to Try LINE Login to use the LINE Login iOS starter application.

Before you begin

Make sure you have the following:

Configuring your channel

To link your app with your channel, complete the following fields in the "App settings" page of the console.

  • iOS bundle ID: Bundle identifier of your app found in the “General” tab in your Xcode project settings. Must be lowercase. For example, com.example.app. You can specify multiple bundle identifiers by entering each one on a new line.
  • iOS scheme: Set as line3rdp. followed by the bundle identifier. For example, if your bundle identifier is com.example.app, set the iOS scheme as line3rdp.com.example.app. Only one iOS scheme can be specified.

iOS app settings

Downloading the SDK

You can download the LINE SDK for iOS using Cocoapods or from the "Downloads" page.

Download with Cocoapods

To download the SDK, add the following line to your Podfile. Note: If you are using Swift, make sure use_frameworks! is specified in your Podfile.

pod 'LineSDK', '~> 4.0.2'

After installing the SDK, continue with the instructions for setting up the SDK from Enable Keychain Sharing.

Download from the "Downloads" page

To download the SDK, go to the Downloads page. Note: We recommend using the latest version of the SDK. The previous versions of the SDK have been deprecated.

Installing the SDK

Add the following frameworks from “Link Binary With Libraries” of the “Build Phases” section of your Xcode project.

  • LineSDK.framework
  • CoreTelephony.framework
  • Security.framework

Set required build settings

Add -ObjC to Build Settings > Other Linker Flags

Enable Keychain Sharing

The LINE iOS SDK uses Keychain to store the user’s authentication credentials. As a result, your application must enable Keychain Sharing to use the SDK.

  1. Enable Keychain Sharing from Capabilities > Keychain Sharing in your Xcode Project settings.
  2. Add the Keychain Sharing entitlement to your entitlements file.
  3. Add the Keychain Sharing feature to your App ID.

Note: Your App ID is found in your Apple developer account.

Configure info.plist settings

Set your channel ID in your application’s Info.plist as follows. Make sure you change “1234567890” to the correct channel ID for your channel. Note: Your channel ID is found in the basic information section of the console.

<key>LineSDKConfig</key>
<dict>
    <key>ChannelID</key>
    <string>1234567890</string>
</dict>  

Add the required settings for app-to-app login to Info.plist. This lets the user automatically log in to your app if they are logged in to the LINE app.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>lineauth</string>
    <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>

Handle app-to-app login in AppDelegate.m

To handle the returned result of the authentication process from the LINE app, add the following code to AppDelegate.m.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
    return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}

Import the LineSDK header file

Import LineSDK.h to all files where the LINE SDK is used.

#import <LineSDK/LineSDK.h>

Setting the LINE login delegate to handle the login results

To listen for and handle the results of the login process, you need to first set the delegate as the view controller where you want to receive the login results. Once you get the results after the user logs in, you can extract and store the user’s access token, user ID, and user profile information in NSStrings. The user profile includes the user’s display name, status message, and profile picture URL.

  1. Set the delegate in the view’s viewDidLoad method
- (void)viewDidLoad {
    [super viewDidLoad];


    ...

    // Set the LINE Login Delegate
    [LineSDKLogin sharedInstance].delegate = self;
}
  1. To handle the login result and store the data, use the didLogin method in LineSDKLoginDelegate.
#pragma mark LineSDKLoginDelegate

- (void)didLogin:(LineSDKLogin *)login
      credential:(LineSDKCredential *)credential
         profile:(LineSDKProfile *)profile
           error:(NSError *)error
{
    if (error) {
        // Login failed with an error. Use the error parameter to identify the problem.
        NSLog(@"Error: %@", error.localizedDescription);
    }
    else {

        // Login success. Extracts the access token, user profile ID, display name, status message, and profile picture.
        NSString * accessToken = credential.accessToken.accessToken;
        NSString * userID = profile.userID;
        NSString * displayName = profile.displayName;
        NSString * statusMessage = profile.statusMessage;
        NSURL * pictureURL = profile.pictureURL;

        NSString * pictureUrlString;

        // If the user does not have a profile picture set, pictureURL will be nil
        if (pictureURL) {
            pictureUrlString = profile.pictureURL.absoluteString;
        }

    }
}

You can get the following information from the parameters from the didLogin method.

Parameter Description
credential Contains the user’s access token.
profile Contains the user’s profile information.
error Contains login error information. This is nil if the login succeeds.

Adding the LINE Login button

To let the user log in to your iOS app, you can create a LINE-branded login button to take the user through the authentication and authorization process.

Note: Make sure you agree to the Usage Guidelines for the LINE Login Button before using the LINE Login button on your app. For more information, see the LINE Login button design guidelines.

Download and add the images to your project

The LINE Login button images set includes images for iOS, Android and desktop applications. The image set also contains images for different resolutions and button states. In this guide, we’ll use the “base” and “press” login button images in the iOS folder.

  1. Download and extract the LINE Login button images from the following link: LINE Login button
  2. Create image sets for the btn_login_press and btn_login_base images by adding them to your Assets.xcassets folder

Note: You can use the sets of images found in the iOS folder. You use the images in either the 32dp or 44dp folders depending on the resolution you want for the images.

Using the images

Before you can use the images, you’ll need to add the login text that you want to use. Find the recommended text for each language on the LINE Login button design guidelines page. You’ll also need to first make the images stretchable without distorting the LINE icon by specifying the end caps of the portion of the image with text.

  1. To make the image stretchable without distorting the LINE icon, go to Editor > Show Slicing.
  2. Click Start Slicing and select the horizontal slicing icon for each of your images.
  3. Add the button to the login screen of your app and add the appropriate login text for your desired language.

Add an action to the button

When the user clicks the login button, the user is authenticated using app-to-app login. With this method, if the user has LINE installed on the device, your app retrieves the user’s LINE credentials from the LINE app to perform authentication. If the LINE app is not installed on the user’s device, the user is redirected to the LINE Login dialog on their browser and prompted for their LINE credentials.

Add a button onclick action to the view controller that calls the startLogin method. The callback function gets the LineSDKLogin sharedInstance common instance and the results are handled in LineSDKLoginDelegate.

- (IBAction)a2alogin:(id)sender {
    NSLog(@"Button pressed: %@");
    [[LineSDKLogin sharedInstance] startLogin];
}

Initializing the LineSDKAPI object

APIs are called through an instance of the LineSDKAPI object. To call APIs, you must initialize the LineSDKAPI object.

apiClient = [[LineSDKAPI alloc] initWithConfiguration:[LineSDKConfiguration defaultConfig]];

Next steps

You have now added LINE Login to your iOS app. Users can log in to your app using their existing LINE accounts while your app can retrieve access tokens and user profile information. For more information on what you can do with LINE Login, see the following articles.