LIINE連携

Prev Next

Classic/VPC環境で利用できます。

LINEログイン機能を使用するためのご利用ガイドです。

LINEの詳細は、LINE Developersをご参照ください。

iOS

Info.plistの設定

  1. プロジェクトの TARGETS > Info > URL Typesに「line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)」を追加します。
  2. プロジェクトの TARGETS > Info > Custom iOS Target Properties > 「Queried URL Schemes」に「lineauth2」を追加します。

Info.plistに直接追加する場合のサンプルコードは次の通りです。

Key Value
CFBundleURLSchemes line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)
LSApplicationQueriesSchemes lineauth2
// Info.plist
<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>lineauth2</string>
</array>

Swift

次のコードを使用して AppDelegate.swiftメソッドのコードを置き換えてください。

// AppDelegate.swift

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
       
        
        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
    }
    
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        let sceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
        
        sceneConfiguration.delegateClass = SceneDelegate.self
        
        return sceneConfiguration
    }

    func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        ...
        // LINEログインコールバック
        NotificationCenter.default.post(name: Notification.Name("LineLoginURL"), object: nil, userInfo: ["application": application, "url": url, "options": options, "type": "AppDelegate"])
        ...
        return true
    }
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let url = URLContexts.first?.url else {
            return
        }

        ...
        // LINEログインコールバック
        NotificationCenter.default.post(name: Notification.Name("LineLoginURL"), object: nil, userInfo: ["url": url, "type": "SceneDelegate"])
        ...
    }

Objective-C

次のコードを使って AppDelegate.mメソッドのコードを置換して追加してください。

// AppDelegate.m
#import "AppDelegate.h"

@interface AppDelegate () <UNUserNotificationCenterDelegate>
@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
    ...
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
    ...
    // LINEログインコールバック
    NSDictionary *userInfo = @{@"application": app, @"url": url, @"options": options, @"type": @"AppDelegate"};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LineLoginURL" object:nil userInfo:userInfo];
    ...
    return YES;
}

次のコードを使って SceneDelegate.mメソッドのコードを置換して追加してください。

// SceneDelegate.m

#import "SceneDelegate.h"

@interface SceneDelegate ()

@end

@implementation SceneDelegate
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
    NSURL *url = URLContexts.allObjects.firstObject.URL;
    if (!url) return;
    
    // LINEログインコールバック
    NSDictionary *userInfo = @{@"url": url, @"type": @"SceneDelegate"};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LineLoginURL" object:nil userInfo:userInfo];
}