将 Adapty Android SDK 迁移到 v. 3.3
Adapty SDK 3.3.0 是一个主要版本,带来了一些改进,但这些改进可能需要您执行一些迁移步骤。
- 更新在非付费墙编辑工具创建的付费墙中处理购买的方式。停止处理
USER_CANCELED和PENDING_PURCHASE错误码。取消购买不再被视为错误,现在将出现在非错误的购买结果中。 - 对于使用付费墙编辑工具创建的付费墙,将
onPurchaseCanceled和onPurchaseSuccess事件替换为新的onPurchaseFinished事件。此更改的原因相同:取消购买不再被视为错误,将被包含在非错误的购买结果中。 - 更改付费墙编辑工具付费墙的
onAwaitingSubscriptionUpdateParams方法签名。 - 如果您直接传递文件 URI,请更新提供备用付费墙的方法。
- 更新 Adjust、AirBridge、Amplitude、AppMetrica、Appsflyer、Branch、Facebook Ads、Firebase 和 Google Analytics、Mixpanel、OneSignal、Pushwoosh 的集成配置。
更新购买流程
以前,取消和待处理的购买被视为错误,并分别返回 USER_CANCELED 和 PENDING_PURCHASE 代码。
现在,使用新的 AdaptyPurchaseResult 类来表示已取消、成功和待处理的购买。按如下方式更新购买代码:
Adapty.makePurchase(activity, product) { result ->
when (result) {
is AdaptyResult.Success -> {
- val info = result.value
- val profile = info?.profile
-
- if (profile?.accessLevels?.get("YOUR_ACCESS_LEVEL")?.isActive == true) {
- // Grant access to the paid features
- }
+ when (val purchaseResult = result.value) {
+ is AdaptyPurchaseResult.Success -> {
+ val profile = purchaseResult.profile
+ if (profile.accessLevels["YOUR_ACCESS_LEVEL"]?.isActive == true) {
+ // Grant access to the paid features
+ }
+ }
+
+ is AdaptyPurchaseResult.UserCanceled -> {
+ // Handle the case where the user canceled the purchase
+ }
+
+ is AdaptyPurchaseResult.Pending -> {
+ // Handle deferred purchases (e.g., the user will pay offline with cash
+ }
+ }
}
is AdaptyResult.Error -> {
val error = result.error
// Handle the error
}
}
}
完整代码示例,请查看在移动应用中进行购买页面。
修改付费墙编辑工具购买事件
-
添加
onPurchaseFinished事件:+ public override fun onPurchaseFinished( + purchaseResult: AdaptyPurchaseResult, + product: AdaptyPaywallProduct, + context: Context, + ) { + when (purchaseResult) { + is AdaptyPurchaseResult.Success -> { + // Grant access to the paid features + } + is AdaptyPurchaseResult.UserCanceled -> { + // Handle the case where the user canceled the purchase + } + is AdaptyPurchaseResult.Pending -> { + // Handle deferred purchases (e.g., the user will pay offline with cash) + } + } + }完整代码示例,请查看成功、取消或待处理购买及事件说明。
-
移除
onPurchaseCancelled事件的处理:- public override fun onPurchaseCanceled( - product: AdaptyPaywallProduct, - context: Context, - ) {} -
移除
onPurchaseSuccess:- public override fun onPurchaseSuccess( - profile: AdaptyProfile?, - product: AdaptyPaywallProduct, - context: Context, - ) { - // Your logic on successful purchase - }
更改 onAwaitingSubscriptionUpdateParams 方法的签名
现在,如果在另一个订阅仍处于活跃状态时购买了新订阅,若新订阅应替换当前活跃订阅,请调用 onSubscriptionUpdateParamsReceived(AdaptySubscriptionUpdateParameters...));若活跃订阅应继续保持活跃且新订阅应单独添加,则调用 onSubscriptionUpdateParamsReceived(null):
- public override fun onAwaitingSubscriptionUpdateParams(
- product: AdaptyPaywallProduct,
- context: Context,
- ): AdaptySubscriptionUpdateParameters? {
- return AdaptySubscriptionUpdateParameters(...)
- }
+ public override fun onAwaitingSubscriptionUpdateParams(
+ product: AdaptyPaywallProduct,
+ context: Context,
+ onSubscriptionUpdateParamsReceived: SubscriptionUpdateParamsCallback,
+ ) {
+ onSubscriptionUpdateParamsReceived(AdaptySubscriptionUpdateParameters(...))
+ }
请参阅升级订阅文档部分获取最终代码示例。
更新提供备用付费墙的方式
如果您通过传递文件 URI 来提供备用付费墙,请按以下方式更新:
更新第三方集成 SDK 配置
为确保集成能与 Adapty Android SDK 3.3.0 及更高版本正常工作,请按照以下各节所述更新以下集成的 SDK 配置。
Adjust
按如下所示更新您的移动应用代码。完整代码示例,请查看 Adjust 集成的 SDK 配置。
AirBridge
按如下所示更新您的移动应用代码。完整代码示例,请查看 AirBridge 集成的 SDK 配置。
Airbridge.getDeviceInfo().getUUID(object: AirbridgeCallback.SimpleCallback<String>() {
override fun onSuccess(result: String) {
- val params = AdaptyProfileParameters.Builder()
- .withAirbridgeDeviceId(result)
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("airbridge_device_id", result) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
override fun onFailure(throwable: Throwable) {
}
})
Amplitude
按如下所示更新您的移动应用代码。完整代码示例,请查看 Amplitude 集成的 SDK 配置。
// For Amplitude maintenance SDK (obsolete)
val amplitude = Amplitude.getInstance()
val amplitudeDeviceId = amplitude.getDeviceId()
val amplitudeUserId = amplitude.getUserId()
//for actual Amplitude Kotlin SDK
val amplitude = Amplitude(
Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
)
)
val amplitudeDeviceId = amplitude.store.deviceId
val amplitudeUserId = amplitude.store.userId
//
- val params = AdaptyProfileParameters.Builder()
- .withAmplitudeDeviceId(amplitudeDeviceId)
- .withAmplitudeUserId(amplitudeUserId)
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("amplitude_user_id", amplitudeUserId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+ Adapty.setIntegrationIdentifier("amplitude_device_id", amplitudeDeviceId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
AppMetrica
按如下所示更新您的移动应用代码。完整代码示例,请查看 AppMetrica 集成的 SDK 配置。
val startupParamsCallback = object: StartupParamsCallback {
override fun onReceive(result: StartupParamsCallback.Result?) {
val deviceId = result?.deviceId ?: return
- val params = AdaptyProfileParameters.Builder()
- .withAppmetricaDeviceId(deviceId)
- .withAppmetricaProfileId("YOUR_ADAPTY_CUSTOMER_USER_ID")
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("appmetrica_device_id", deviceId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+
+ Adapty.setIntegrationIdentifier("appmetrica_profile_id", "YOUR_ADAPTY_CUSTOMER_USER_ID") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
override fun onRequestError(
reason: StartupParamsCallback.Reason,
result: StartupParamsCallback.Result?
) {
// Handle the error
}
}
AppMetrica.requestStartupParams(context, startupParamsCallback, listOf(StartupParamsCallback.APPMETRICA_DEVICE_ID))
AppsFlyer
按如下所示更新您的移动应用代码。完整代码示例,请查看 AppsFlyer 集成的 SDK 配置。
val conversionListener: AppsFlyerConversionListener = object : AppsFlyerConversionListener {
override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
- Adapty.updateAttribution(
- conversionData,
- AdaptyAttributionSource.APPSFLYER,
- AppsFlyerLib.getInstance().getAppsFlyerUID(context)
- ) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ val uid = AppsFlyerLib.getInstance().getAppsFlyerUID(context)
+ Adapty.setIntegrationIdentifier("appsflyer_id", uid) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+ Adapty.updateAttribution(conversionData, "appsflyer") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
}
Branch
按如下所示更新您的移动应用代码。完整代码示例,请查看 Branch 集成的 SDK 配置。
// Login and update attribution
Branch.getAutoInstance(this)
.setIdentity("YOUR_USER_ID") { referringParams, error ->
referringParams?.let { data ->
- Adapty.updateAttribution(data, AdaptyAttributionSource.BRANCH) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.updateAttribution(data, "branch") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
}
// Logout
Branch.getAutoInstance(context).logout()
Facebook Ads
按如下所示更新您的移动应用代码。完整代码示例,请查看 Facebook Ads 集成的 SDK 配置。
- val builder = AdaptyProfileParameters.Builder()
- .withFacebookAnonymousId(AppEventsLogger.getAnonymousAppDeviceGUID(context))
-
- Adapty.updateProfile(builder.build()) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier(
+ "facebook_anonymous_id",
+ AppEventsLogger.getAnonymousAppDeviceGUID(context)
+ ) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
Firebase 和 Google Analytics
按如下所示更新您的移动应用代码。完整代码示例,请查看 Firebase 和 Google Analytics 集成的 SDK 配置。
Mixpanel
按如下所示更新您的移动应用代码。完整代码示例,请查看 Mixpanel 集成的 SDK 配置。
- val params = AdaptyProfileParameters.Builder()
- .withMixpanelUserId(mixpanelAPI.distinctId)
- .build()
-
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("mixpanel_user_id", mixpanelAPI.distinctId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
OneSignal
按如下所示更新您的移动应用代码。完整代码示例,请查看 OneSignal 集成的 SDK 配置。
Pushwoosh
按如下所示更新您的移动应用代码。完整代码示例,请查看 Pushwoosh 集成的 SDK 配置。