Skip to main content

Dragonpass Hybrid SDK

  • iOS SDK
  • Android SDK

iOS SDK

Compatibility

Your project must target iOS 13 or later. Swift projects should use Swift 5.6 or later, and CocoaPods 1.8.1 or later is required.

Installation

For manual installation with Swift Package Manager:

  1. In Xcode, select File → Add Package Dependencies…
  2. Enter the repository URL for the Dragonpass Hybrid SDK:
    Terminal
    https://github.com/bigBandFE/dpsdk-ios-spm
  3. Set the Dependency Rule to Branchmain.
  4. Click Add Package, select product DPSDKKit.

Use this AI-assisted workflow to inspect the host app, add DPSDKKit, initialize DPSDK, set the auth code, open DPApps, and verify the build. Install the skill with:

Terminal
hermes skills install --category devops --yes \
"https://raw.githubusercontent.com/bigBandFE/dpsdk-ai-skill/main/SKILL.md"

Launch DPApp

  1. Import the SDK

    Swift
    import DPSDKKit
  2. Initialize the SDK Replace client_id with your actual client ID:

    Swift
    DPSDK.start(clientId: "client_id")
  3. Set Auth Code After obtaining the auth code from Connect, pass it to the SDK:

    Swift
    DPSDK.shared.setAuthCode(token: "xxxxx")

    See Connect for the full authentication flow.

  4. Open DPApp

    UIKit

    Swift
    DPSDK.open(
    appId: "app_id",
    params: ["path": "introduction"],
    from: viewController
    )

    SwiftUI

    Swift
    // If using SwiftUI, you must obtain the current UIViewController.
    struct ContentView: View {
    var body: some View {
    VStack {
    Button("Open DPSDK (Create)") {
    openDPSDKWithCreate()
    }
    }
    }

    private func openDPSDKWithCreate() {
    guard let viewController = getCurrentViewController() else {
    print("Unable to get current ViewController")
    return
    }

    DPSDK.createViewController(
    appId: "your_app_id",
    path: "home",
    params: ["demo": "custom_navigation"]
    ) { createdViewController, error in
    guard let DPAppVC = createdViewController else {
    print("Creation failed: \(error?.localizedDescription ?? "Unknown error")")
    return
    }

    DispatchQueue.main.async {
    if let navController = viewController.navigationController {
    navController.pushViewController(DPAppVC, animated: true)
    } else {
    let nav = UINavigationController(rootViewController: DPAppVC)
    nav.modalPresentationStyle = .fullScreen
    viewController.present(nav, animated: true)
    }
    }
    }
    }

    private func getCurrentViewController() -> UIViewController? {
    guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
    let window = windowScene.windows.first else {
    return nil
    }
    return window.rootViewController?.topMostViewController()
    }
    }

Language Configuration

Swift
DPSDKConfigManager.shared.setLanguage("en-US")

DPApp URL Listener

Swift
// To listen for URL change events:
DPApp.delegate = self

extension ViewController: DPAppCustomDelegate {
func didDPAppChangeUrlEvent(DPApp: DPApp, url: URL) {
if url.path.components(separatedBy: "/").contains("details") {
print("Search url: \(url)")
}
}
}

Custom Event Handling

Swift
func dpAppHandleCustomEvent(_ event: SparkAppCustomEvent, completion: @escaping (SparkAppResponse) -> Void) {
switch event.type {
case "getUserInfo":
if !isLogin() || getUserInfo() == nil {
completion(SparkAppResponse(statusCode: 0, errCode: "USER_NOT_LOGIN", msg: "User is not logged in"))
} else {
let userInfo: [String: Any] = [
"id": getUserInfo()?["id"] ?? "",
"firstName": getUserInfo()?["firstName"] ?? "",
"lastName": getUserInfo()?["lastName"] ?? ""
]
completion(SparkAppResponse(statusCode: 1, data: userInfo))
}
default:
completion(SparkAppResponse(statusCode: 0, errCode: "APP_10001", msg: "Unknown event type: \(event.type)"))
}
}

Append Custom Params to DPApp URL

Swift
let config = [
"path": "introduction",
"orderId": "123123"
]

DPSDK.open(
appId: "app_id",
params: config,
from: viewController
)

DPApp Lifecycle Events

Swift
DPApp.delegate = self

extension ViewController: DPAppCustomDelegate {
func dpAppDidLaunch(_ event: DPAppLifecycleEvent) {}
func dpAppDidShow(_ event: DPAppLifecycleEvent) {}
func dpAppDidHide(_ event: DPAppLifecycleEvent) {}
func dpAppDidResume(_ event: DPAppLifecycleEvent) {}
func dpAppDidClose(_ event: DPAppLifecycleEvent) {}
func dpAppDidError(_ event: DPAppLifecycleEvent, error: String) {}
}

Android SDK

Compatibility

Your project must target Android 5.0 (API level 21) or higher.

Installation

For manual installation with Gradle / JitPack:

Add JitPack to dependency resolution:

Kotlin
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}

Add the dependency to your app module:

Kotlin
dependencies {
implementation("com.github.bigBandFE:dpsdk-android:2.0.0")
}

Add the following to gradle.properties:

properties
android.enableJetifier=true

Use this AI-assisted workflow to inspect the host app, add the SDK dependency, initialize DPSDK, set the auth code, open DPApps, and verify the build. Install the skill from the official GitHub SKILL.md URL:

Terminal
hermes skills install --category devops --yes \
"https://raw.githubusercontent.com/bigBandFE/dpsdk-ai-skill/main/SKILL.md"

Launch DPApp

  1. Initialize in Application Class

    Kotlin
    class MyApplication : Application() {
    override fun onCreate() {
    super.onCreate()
    DPSDK.init(this).setDPSdkConfig(
    DPSDKConfig.Builder()
    .setClientId("<client_id>")
    .build()
    )
    }
    }
  2. Register in AndroidManifest.xml

    XML
    <application
    android:name=".MyApplication"
    ...>
  3. Set Auth Code After obtaining the auth code from Connect, pass it to the SDK:

    Kotlin
    DPSDK.setAuthCode("xxxxx")

    See Connect for the full authentication flow.

  4. Open DPApp

    Kotlin
    val appId = "<app_id>"
    DPSDK.getDPApp(appId).open(this)

Language Configuration

Kotlin
DPSDK.getDPSdkConfig().setLanguage("en-US")

DPApp URL Listener

Kotlin
val appId = "<app_id>"
val dpApp = DPSDK.getDPApp(appId)
dpApp.setUrlChangeListener { activity: FragmentActivity, url: URL? ->
Log.e("URL Path", url?.path ?: "")
}.open(this)

Custom Event Handling

Kotlin
val appId = "<app_id>"
val dpApp = DPSDK.getDPApp(appId)

dpApp?.setCustomEventListener { activity, data, jsCustomEventMsgEntity, callBackFunction ->
val eventType = jsCustomEventMsgEntity.eventType
when (eventType) {
"getUserInfo" -> {
getUserInfo(activity, data, jsCustomEventMsgEntity, callBackFunction)
}
}
}
private fun getUserInfo(
activity: FragmentActivity,
data: String?,
jsCustomEventMsgEntity: JsCustomEventMsgEntity,
function: CallBackFunction?
): Boolean {
if (!LoginUtils.isLogin() || LoginUtils.getUserInfo() == null) {
function?.onFailure("errorCode", "errorMsg")
} else {
val hashMapOf = hashMapOf<String, Any?>()
hashMapOf["id"] = "xxxxx"
hashMapOf["firstName"] = "xxxxx"
hashMapOf["lastName"] = "xxxxx"
function?.onSuccess(hashMapOf)
}
return true
}

Append Custom Params to DPApp URL

Kotlin
val appId = "<app_id>"
val dpApp = DPSDK.getDPApp(appId)

dpApp?.setDPAppConfig(
DPAppConfig.Builder()
.setExtraUrlParams(hashMapOf<String, String>().apply {
put("order_no", "xxx")
})
.build()
)?.open(mContext, "order-detail")

DPApp Lifecycle Events

Kotlin
val appId: String = "<app_id>"
val dpApp: DPApp = DPSDK.getDPApp(appId)

dpApp.setDPAppLifecycleListener(object : DPAppLifecycleListener {
override fun onLaunch(activity: FragmentActivity, dpApp: DPApp?, pageName: String) {}

override fun onResume(activity: FragmentActivity, dpApp: DPApp?, pageName: String) {}

override fun onPause(activity: FragmentActivity, dpApp: DPApp?, pageName: String) {}

override fun onClose(activity: FragmentActivity, dpApp: DPApp?, pageName: String) {}

override fun onError(activity: FragmentActivity, dpApp: DPApp?, pageName: String) {}
})