経緯
Line連携実装したく、実機で自身のLineアカウントのプロフィールを取得する
テストアプリを作成しています。
テストアプリ完成イメージ
MUSHIKAGO APPS MEMOさんのこの記事の以下の写真部分までが実現したいテストアプリの完成状態です
参考にしたサイト
LineSDK公式:ここは一から順番に実施しました
追憶行:コードはこちらを拝借しています。*一部エラーが出て変更
困りごと
分析(下記)しても特段のエラーはないように見えるにも関わらず、プロフィールが取得できない。
エラー詳細
エラー①内容
[LineSDK] Trying to start another login process while the previous one still valid. This login process is ignore. Set `allowRecreatingLoginProcess` in login parameterif you want to allow this action.
エラー②内容
2020-01-12 04:39:21.180639+0900 LineLogin[12494:4817465] Can't end BackgroundTask: no background task exists with identifier 2 (0x2), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
ソースコード
####### ファイル構成
一部cocoapods構成でうまくいかずやり直した経緯があるので、
構成が正しいのか自信がないです。
####### LoginViewController.swift
swift
1import UIKit 2import Foundation 3import LineSDK 4 5class LineViewController: UIViewController { 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 } 9 10 @IBAction func login(_ sender: Any) { 11 LoginManager.shared.login(permissions: [.profile], in: self) { 12 result in 13 switch result { 14 case .success(let loginResult): 15 print("throw") 16 if let profile = loginResult.userProfile { 17 print("User ID: (profile.userID)") 18 print("User Display Name: (profile.displayName)") 19 print("User Icon: (String(describing: profile.pictureURL))") 20 } 21 case .failure(let error): 22 print(error) 23 } 24 } 25 } 26}
####### エラーを返している部分(LineSDK内 : LoginConfiguration.swift)
swift
1/// Logs in to the LINE Platform. 2 /// 3 /// - Parameters: 4 /// - permissions: The set of permissions requested by your app. The default value is 5 /// `[.profile]`. 6 /// - viewController: The the view controller that presents the login view controller. If `nil`, the topmost 7 /// view controller in the current view controller hierarchy will be used. 8 /// - parameters: The parameters used during the login process. For more information, 9 /// see `LoginManager.Parameters`. 10 /// - completion: The completion closure to be invoked when the login action is finished. 11 /// - Returns: The `LoginProcess` object which indicates that this method has started the login process. 12 /// 13 /// - Note: 14 /// Only one process can be started at a time. Do not call this method again to start a new login process 15 /// before `completion` is invoked. 16 /// 17 /// If the value of `permissions` contains `.profile`, the user profile will be retrieved during the login 18 /// process and contained in the `userProfile` property of the `LoginResult` object in `completion`. 19 /// Otherwise, the `userProfile` property will be `nil`. Use this profile to identify your user. For 20 /// more information, see `UserProfile`. 21 /// 22 /// An access token will be issued if the user authorizes your app. This token and a refresh token 23 /// will be automatically stored in the keychain of your app for later use. You do not need to 24 /// refresh the access token manually because any API call will attempt to refresh the access token if 25 /// necessary. However, if you need to refresh the access token manually, use the 26 /// `API.Auth.refreshAccessToken(with:)` method. 27 /// 28 @discardableResult 29 public func login( 30 permissions: Set<LoginPermission> = [.profile], 31 in viewController: UIViewController? = nil, 32 parameters: LoginManager.Parameters = .init(), 33 completionHandler completion: @escaping (Result<LoginResult, LineSDKError>) -> Void 34 ) -> LoginProcess? 35 { 36 lock.lock() 37 defer { lock.unlock() } 38 39 if !parameters.allowRecreatingLoginProcess && isAuthorizing { 40 Log.print("Trying to start another login process while the previous one still valid. " + 41 "This login process is ignore. Set `allowRecreatingLoginProcess` in login parameter" + 42 "if you want to allow this action.") 43 return nil 44 } 45 46 if parameters.allowRecreatingLoginProcess && isAuthorizing { 47 if let process = currentProcess { 48 self.currentProcess?.onFail.call( 49 LineSDKError.generalError(reason: .processDiscarded(process)) 50 ) 51 } else { 52 Log.assertionFailure("The current process should exist. If you trigger this failure," + 53 " please report on the issue page: https://github.com/line/line-sdk-ios-swift/issues") 54 } 55 } 56 57 let process = LoginProcess( 58 configuration: LoginConfiguration.shared, 59 scopes: permissions, 60 parameters: parameters, 61 viewController: viewController) 62 process.onSucceed.delegate(on: self) { [unowned process] (self, result) in 63 self.currentProcess = nil 64 self.postLogin( 65 token: result.token, 66 response: result.response, 67 process: process, 68 completionHandler: completion) 69 } 70 process.onFail.delegate(on: self) { (self, error) in 71 self.currentProcess = nil 72 completion(.failure(error.sdkError)) 73 } 74 75 process.start() 76 77 self.currentProcess = process 78 return currentProcess 79 }
allowRecreatingLoginProcessの宣言部分
/// Sets the nonce value for ID token verification. This value is used when requesting user authorization /// with `.openID` permission to prevent replay attacks to your backend server. If not set, LINE SDK will /// generate a random value as the token nonce. Whether set or not, LINE SDK verifies against the nonce value /// in received ID token locally. public var IDTokenNonce: String? = nil #if targetEnvironment(macCatalyst) public var allowRecreatingLoginProcess = true #else public var allowRecreatingLoginProcess = false #endif
isAuthorizingの宣言部分
/// Checks and returns whether the authorizing process is currently ongoing. public var isAuthorizing: Bool { return currentProcess != nil }
エラー①分析
login関数内にBreakPointを設置してloginボタン押下直後のパラメーター
Printing description of parameters: ▿ Parameters - onlyWebLogin : false - botPromptStyle : nil - preferredWebPageLanguage : nil - IDTokenNonce : nil - allowRecreatingLoginProcess : false
上記ログイン関数内の[!parameters.allowRecreatingLoginProcess && isAuthorizing]にひかかっており、
parameters.allowRecreatingLoginProcessはこの時点でfalseなので、if条件としては、
!parameters.allowRecreatingLoginProcess //true
かつ
isAuthorizing true
でこのif分に入っていることは理解できた。
ただ、これはlog出すだけで、その後のlet process = LoginProcessには入っていくように見えます。
そこで、そこにBreakPoint設置して、loginボタン押下。processの中身は↓
これを見る限り悪いところがわかりませんでした。
###エラー②分析
こちらに関しては、stackoverflowにてiOS13特有の問題だとのコメントを見つけました。
Finally I've created an empty project Single View App. Only code generated by Xcode, I run the app on simulator, put it in background and I see the same warning. So I can say it's an iOS 13 issue. I hope Apple will fix it quickly because in Crashlytics I found some crash in my app caused by it.
ここまでの分析の結果、プロセス流れているように見えるのに、結果が返ってこない。と言う感じで
暗礁に乗り上げてしまっています。
どなたかご教授頂けると幸いです。
あなたの回答
tips
プレビュー