Skip to content

Commit

Permalink
Gotta keep the reference to TangemSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
megakoko committed Apr 25, 2023
1 parent d7f66e5 commit 09d9795
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ios/Classes/SwiftTangemSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import UIKit
import TangemSdk

public class SwiftTangemSdkPlugin: NSObject, FlutterPlugin {
private var _sdk: Any?

public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "tangemSdk", binaryMessenger: registrar.messenger())
let instance = SwiftTangemSdkPlugin()
Expand Down Expand Up @@ -37,12 +39,20 @@ public class SwiftTangemSdkPlugin: NSObject, FlutterPlugin {
let cardId: String? = getArg(for: .cardId, from: args)
let initialMessage: String? = getArg(for: .initialMessage, from: args)

let sdk = TangemSdk()
let sdk = self.sdk()
sdk.startSession(with: request,
cardId: cardId,
initialMessage: initialMessage) { completion($0) }
}


@available(iOS 13.0, *)
private func sdk() -> TangemSdk {
if _sdk == nil {
_sdk = TangemSdk()
}
return _sdk as! TangemSdk
}

private func getArg<T>(for key: ArgKey, from arguments: Any?) -> T? {
if let value = (arguments as? NSDictionary)?[key.rawValue] {
return value as? T
Expand Down

0 comments on commit 09d9795

Please sign in to comment.