深色模式

開始使用

設定 appKey

appKey 是發給你們的公開識別值,格式如 ak_xxx,用來辨識是哪個 App;請放在本機、不進版控的設定檔,由 build 系統注入。

  • appKey 不是密碼,但不應寫進版控或公開文件,以免混淆不同環境。
  • 單獨持有 appKey 換不到資料 token;SDK 會再以平台裝置驗證換取短期 token。
  • 測試環境另有「測試環境驗證碼」,由我方另行提供,注入方式與 appKey 相同,不要寫死在程式裡。
待確認:appKey 的申請方式。目前由我方直接提供。

iOS

  1. 建立 Config/Local.xcconfig,並確認它被 .gitignore 忽略。
Config/Local.xcconfig
LAPID_APP_KEY = ak_xxx
LAPID_TEST_ATTESTATION = xxx
  1. Debug、Release 的 xcconfig 以 #include? "Local.xcconfig" 引用它。缺檔時不會報錯,但缺值時 SDK 會丟錯。
  2. 在 Info.plist 新增鍵 LapidAppKey,值為 $(LAPID_APP_KEY),Xcode 會展開成 xcconfig 的值。試點期另加 LapidTestAttestation,值為 $(LAPID_TEST_ATTESTATION)。
  3. 以 LapidConfiguration.fromInfoPlist 建立設定。
iOS
import LapidSDK

let testAttestation = Bundle.main.object(forInfoDictionaryKey: "LapidTestAttestation") as? String ?? ""
let config = try LapidConfiguration.fromInfoPlist(
    baseURL: URL(string: "https://sdk-api.lapidinsight.com")!,
    attestation: DebugAttestationProvider(payload: testAttestation)
)
let client = LapidClient(configuration: config)

Info.plist 缺值、為空白或未展開時,會丟出 LapidConfigurationError.missingAppKey,訊息會指出要設定的鍵名。

Android

  1. 在專案根目錄的 local.properties(Android 預設已被 .gitignore 忽略)加入:
local.properties
lapid.appKey=ak_xxx
lapid.testAttestation=xxx
  1. 在 app/build.gradle.kts 把它注入 manifest 佔位。
app/build.gradle.kts
val localProps = java.util.Properties().apply {
    rootProject.file("local.properties").takeIf { it.isFile }?.inputStream()?.use { load(it) }
}

android {
    defaultConfig {
        manifestPlaceholders["lapidAppKey"] = localProps.getProperty("lapid.appKey", "")
        // 試點期:測試環境驗證碼,只放 debug 用途
        buildConfigField("String", "LAPID_TEST_ATTESTATION", "\"${localProps.getProperty("lapid.testAttestation", "")}\"")
    }
    buildFeatures { buildConfig = true }
}
  1. 在 AndroidManifest.xml 的 application 內加入 meta-data。
AndroidManifest.xml
<meta-data android:name="com.rytass.lapid.APP_KEY" android:value="${lapidAppKey}" />
  1. 以 LapidConfig.fromManifest 建立設定。
Android
val config = LapidConfig.fromManifest(
    context = this,
    baseUrl = "https://sdk-api.lapidinsight.com",
    attestation = DebugAttestationProvider(BuildConfig.LAPID_TEST_ATTESTATION),
)
val client = LapidClient(this, config)

缺值時丟出 LapidConfigException,訊息會指出要設定的 meta-data 名稱。

Web

Web SDK 的設定沒有 appKey。token 由你的後端取得後,交給 tokenSource,詳見「第一個請求」與「授權與限流」。