Initialize

To initialize the SDK, call the initFordefiSDK method. Most developers should pass null and use the default configuration, so:

async function initSdk() {
   try {
       await initFordefiSDK({
           baseURL: 'https://api.fordefi.com'
       });
   console.log('SDK was initiated successfully!');
   } catch (e) {
       const error = e as FordefiSdkErrorResult;
       console.log(
           `there was an error. error code :${error.code}, error message: ${error.message}`
       );
   }
}
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import com.fordefi.fordefi.Fordefi
import com.fordefi.fordefi.FordefiConfiguration

class MainActivity: ComponentActivity() {
    private
    var fordefi: Fordefi ? = null

    override fun onCreate(savedInstanceState: Bundle ? ) {
      super.onCreate(savedInstanceState)

      fordefi = Fordefi.getInstance(applicationContext,
        FordefiConfiguration("https://api.fordefi.com")
      )
      setupLifecycleObserver()
    }

    private fun setupLifecycleObserver() {
      ProcessLifecycleOwner.get().lifecycle.addObserver(
        object: DefaultLifecycleObserver {
          override fun onStart(owner: LifecycleOwner) {
            fordefi!!.notifyAppStateChanged(FordefiAppState.Foreground)
          }

          override fun onStop(owner: LifecycleOwner) {
            fordefi!!.notifyAppStateChanged(FordefiAppState.Background)
          }
        })
    }
import FordefiSdk

class ViewController: UIViewController {
  private var fordefi: Fordefi?
  override func viewDidAppear(_ animated: Bool) {
    do {
      self.fordefi = try Fordefi.getInstance(
        configuration: FordefiConfiguration(
          baseURL: "https://api.fordefi.com"
        ))
    } catch let error {
      print("Failed to initialize Fordefi. Error: \(error.localizedDescription)")
      return
    }
  }

  @objc func appWillEnterForeground() {
    self.fordefi?.notifyAppStateChanged(appState: .foreground)
  }

  @objc func appDidEnterBackground() {
    self.fordefi?.notifyAppStateChanged(appState: .background)
  }
}