Skip to content

Instantly share code, notes, and snippets.

@ohtsuchi
Last active March 19, 2019 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohtsuchi/d2e13266f0772477556c8cdb8d6c199d to your computer and use it in GitHub Desktop.
Save ohtsuchi/d2e13266f0772477556c8cdb8d6c199d to your computer and use it in GitHub Desktop.
LINE SDK for iOS Swift Version 5 設定メモ

LINE SDK for iOS Swift Version 5 設定メモ

参考サイト(公式)

[1] CocoaPods で SDK インストール

$ pod init
  • Podfile 追記
pod 'LineSDKSwift', '~> 5.0'
$ pod install

[2] XCode 起動

  • .xcworkspace をダブルクリックして XCode 起動
  • Cmd + B を実行して ビルド

[3] チャネル 作成

  • LINE Developers にログイン、プロバイダー登録
  • チャネル を作成
  • アプリ設定
    • iOS bundle ID, iOS scheme を設定
      • iOS scheme の値 = line3rdp.<iOS bundle ID の値>

[4] Info.plist ファイルを設定

  • Info.plist に 以下の内容で XML を追記
    <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>

[5] AppDelegate.swift 実装

  • import 追加
import LineSDK
  • application(_:didFinishLaunchingWithOptions:) 内で LoginManager.setup() を呼び出す
    • "YOUR_CHANNEL_ID" の部分は 上記 [3] で作成した 「チャネル」 の Channel ID に置き換え
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // ★ 以下の1行を追加
    LoginManager.shared.setup(channelID: "YOUR_CHANNEL_ID", universalLinkURL: nil)
    return true
  }
  • application(_:open:options:) メソッドを新規追加。中で LoginManager.application() を呼び出す
  // ★メソッドごと、新規追加
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return LoginManager.shared.application(app, open: url, options: options)
  }

[6] ViewController.swift 実装

  • import 追加
import LineSDK
  • ログイン の 実装
  func login() {
    LoginManager.shared.login(permissions: [.profile], in: self) {
      result in
      switch result {
      case .success(let loginResult):
        if let profile = loginResult.userProfile {
          print("User ID: \(profile.userID)")
          print("User Display Name: \(profile.displayName)")
          print("User Icon: \(String(describing: profile.pictureURL))")

          // TODO 実装追加
        }
      case .failure(let error):
        print(error)
      }
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment