# Migrate from Old SDK

### Updating the old repository

Formerly we had:

```kotlin
maven { 
  url = uri("https://artifactory.datalf.chat/artifactory/app-consent-v2-release")
}
```

From now on, it is necessary to:

```kotlin
maven { 
  url = uri("https://artifactory.datalf.chat/artifactory/appconsent")
}
```

### Implementation change

Previously, we had:

```kotlin
dependencies { 
    implementation("com.sfbx.appconsent:appconsent-ui-v3:X.Y.Z")
}
```

From now on, you must:

```kotlin
dependencies { 
    implementation("io.sfbx.appconsent:unifiedsdk:X.Y.Z")
}
```

### Change in integration

#### Imports

Before we had:

```kotlin
import com.sfbx.appconsentv3.*
```

Now the imports are as follows:

```kotlin
import io.sfbx.appconsent.unifiedsdk.*
```

#### Initializing the SDK

This is very similar to the old SDK (like many other libraries).

Before, we had:

1. Initialization of the SDK
2. Registration of callbacks to intercept the user's response
3. Attempt to display the CMP
4. Deletion of callbacks regardless of the result

```kotlin
AppConsentSDK.initialize(
  appKey = "YOUR_APP_KEY"
) { appConsentInitialized ->
  appConsentInitialized.setOnPresentNoticeListener(object : OnPresentNoticeListener {
    override fun presentConsentError(error: Throwable?) {
      appConsentInitialized.setOnPresentNoticeListener(null)
    }

     override fun presentConsentGiven() {
       appConsentInitialized.setOnPresentNoticeListener(null)
     }
  })
  
  if(false == appConsentInitialized.tryToDisplayNoticeFromUiContext(uiContext = this@MainActivity, force = false)) {
    appConsentInitialized.setOnPresentNoticeListener(null)
  }
}
```

Now :

1. Initializing the SDK
2. Display request (the display & consent response is returned directly in the method callbacks)

```kotlin
SFBX.initialize(
  context = this@MyActivity.context,
  configuration = Configuration(appkey = "YOUR-APP-KEY"),
  onCmpReady = { appconsent ->
    appconsent.presentNotice(
      context = context,
      onCmpDisplayed = { },
      onCmpNotDisplayed = { },
      onCmpClosed = { },
    )},
  onCmpOnError = { appconsentExceptions ->
     },
)
```

### Displaying the consent screen to your users

This allows your users to view their consent and modify it if necessary.

Before, we had:

```kotlin
AppConsentSDK.getInstance()
  ?.setOnPresentNoticeListener(object : OnPresentNoticeListener {
    override fun presentConsentError(error: Throwable?) {
      AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
    }

    override fun presentConsentGiven() {
      AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
    }
  })

  val isCmpDisplayed =
    AppConsentSDK.getInstance()?.tryToDisplayNotice(force = true) ?: false
  if (false == isCmpDisplayed) {
    AppConsentSDK.getInstance()?.setOnPresentNoticeListener(null)
  }
```

Now :

```kotlin
try {
    SFBX.getInstance()
} catch (_: Exception) {
    null
}?.displayLayer2(context,
    onCmpDisplayed = { },
    onCmpNotDisplayed = { },
    onCmpClosed = { },
)


// Alternatively, the following approach is more idiomatic Kotlin,
// using runCatching to handle the exception in a functional style.


runCatching {
    SFBX.getInstance()
}.onSuccess { appconsent ->
    appconsent.displayLayer2(context,
        onCmpDisplayed = { },
        onCmpNotDisplayed = { },
        onCmpClosed = { },
    )
}.onFailure {
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sfbx.io/configuration/step-3-notice-implementation-web-app-tv/android/unified-sdk/migrate-from-old-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
