Migrate Adapty Unity SDK to v. 3.3
Adapty SDK 3.3.0 is a major release that brought some improvements which however may require some migration steps from you.
- Upgrade to Adapty SDK v3.3.x.
- Renamed multiple classes, properties, and methods in the Adapty and AdaptyUI modules of Adapty SDK.
- From now on, the
SetLogLevel
method accepts a callback as an argument. - From now on, the
PresentCodeRedemptionSheet
method accepts a callback as an argument. - Change how the paywall view is created
- Remove the
GetProductsIntroductoryOfferEligibility
method. - Save fallback paywalls to separate files (one per platform) in
Assets/StreamingAssets/
and pass the file names to theSetFallbackPaywalls
method. - Update making purchase
- Update handling of Paywall Builder events.
- Update handling of Paywall Builder paywall errors.
- Update integration configurations for Adjust, Amplitude, AppMetrica, Appsflyer, Branch, Firebase and Google Analytics, Mixpanel, OneSignal, Pushwoosh.
- Update Observer mode implementation.
- Update the Unity plugin initialization with an explicit
Activate
call.
Upgrade Adapty Unity SDK to 3.3.x
Up to this version, Adapty SDK was the core and mandatory SDK necessary for the proper functioning of Adapty within your app, and AdaptyUI SDK was an optional SDK that becomes necessary only if you use the Adapty Paywall Builder.
Starting with version 3.3.0, AdaptyUI SDK is deprecated, and AdaptyUI is merged to Adapty SDK as a module. Because of these changes, you need to remove AdaptyUISDK and reinstall AdaptySDK.
- Remove both AdaptySDK and AdaptyUISDK package dependencies from your project.
- Delete the AdaptySDK and AdaptyUISDK folders.
- Import the AdaptySDK package again as described in the Adapty SDK installation & configuration for Unity page.
Renamings
-
Rename in Adapty module:
Old version New version Adapty.sdkVersion Adapty.SDKVersion Adapty.LogLevel AdaptyLogLevel Adapty.Paywall AdaptyPaywall Adapty.PaywallFetchPolicy AdaptyPaywallFetchPolicy PaywallProduct AdaptyPaywallProduct Adapty.Profile AdaptyProfile Adapty.ProfileParameters AdaptyProfileParameters ProfileGender AdaptyProfileGender Error AdaptyError -
Rename in AdaptyUI module:
Old version New version CreatePaywallView CreateView PresentPaywallView PresentView DismissPaywallView DismissView AdaptyUI.View AdaptyUIView AdaptyUI.Action AdaptyUIUserAction
Change the SetLogLevel method
From now on, the SetLogLevel
method accepts a callback as an argument.
- Adapty.SetLogLevel(Adapty.LogLevel.Verbose);
+ Adapty.SetLogLevel(Adapty.LogLevel.Verbose, null); // or you can pass the callback to handle the possible error
Change the PresentCodeRedemptionSheet method
From now on, the PresentCodeRedemptionSheet
method accepts a callback as an argument.
- Adapty.PresentCodeRedemptionSheet();
+ Adapty.PresentCodeRedemptionSheet(null); // or you can pass the callback to handle the possible error
Change how the paywall view is created
For the complete code example, check out Fetch the view configuration of paywall designed using Paywall Builder.
+ var parameters = new AdaptyUICreateViewParameters()
+ .SetPreloadProducts(true);
- AdaptyUI.CreatePaywallView(
+ AdaptyUI.CreateView(
paywall,
- preloadProducts: true,
+ parameters,
(view, error) => {
// use the view
});
Remove the GetProductsIntroductoryOfferEligibility method
Before Adapty iOS SDK 3.3.0, the product object always included offers, regardless of whether the user was eligible. You had to manually check eligibility before using the offer.
Now, the product object only includes an offer if the user is eligible. This means you no longer need to check eligibility — if an offer is present, the user is eligible.
Update method for providing fallback paywalls
Up to this version, the fallback paywalls were passed as a serialized JSON. Starting from v 3.3.0, the mechanism is changed:
- Save fallback paywalls to files in
/Assets/StreamingAssets/
, 1 file for Android and another for iOS. - Pass the file names to the
SetFallbackPaywalls
method.
Your code will change this way:
using AdaptySDK;
void SetFallBackPaywalls() {
+ #if UNITY_IOS
+ var assetId = "adapty_fallback_ios.json";
+ #elif UNITY_ANDROID
+ var assetId = "adapty_fallback_android.json";
+ #else
+ var assetId = "";
+ #endif
- Adapty.SetFallbackPaywalls("FALLBACK_PAYWALLS_JSON_STRING", (error) => {
+ Adapty.SetFallbackPaywalls(assetId, (error) => {
// handle the error
});
}
Check out the final code example in the Use fallback paywalls in Unity page.
Update making purchase
Previously canceled and pending purchases were considered errors and returned the PaymentCancelled
and PendingPurchase
codes, respectively.
Now a new AdaptyPurchaseResultType
class is used to process canceled, successful, and pending purchases. Update the code of purchasing in the following way:
using AdaptySDK;
void MakePurchase(AdaptyPaywallProduct product) {
- Adapty.MakePurchase(product, (profile, error) => {
- // handle successfull purchase
+ Adapty.MakePurchase(product, (result, error) => {
+ switch (result.Type) {
+ case AdaptyPurchaseResultType.Pending:
+ // handle pending purchase
+ break;
+ case AdaptyPurchaseResultType.UserCancelled:
+ // handle purchase cancellation
+ break;
+ case AdaptyPurchaseResultType.Success:
+ var profile = result.Profile;
+ // handle successful purchase
+ break;
+ default:
+ break;
}
});
}
Check out the final code example in the Make purchases in mobile app page.
Update handling of Paywall Builder events
Canceled and pending purchases are not considered to be errors any more, all these cases are processed with the PaywallViewDidFinishPurchase
method.
-
Delete processing of the Canceled purchase event.
-
Update handling of the Successful purchase event in the following way:
- public void OnFinishPurchase(
- AdaptyUI.View view,
- Adapty.PaywallProduct product,
- Adapty.Profile profile
- ) { }
+ public void PaywallViewDidFinishPurchase(
+ AdaptyUIView view,
+ AdaptyPaywallProduct product,
+ AdaptyPurchaseResult purchasedResult
+ ) { } -
Update handling of actions:
- public void OnPerformAction(
- AdaptyUI.View view,
- AdaptyUI.Action action
- ) {
+ public void PaywallViewDidPerformAction(
+ AdaptyUIView view,
+ AdaptyUIUserAction action
+ ) {
switch (action.Type) {
- case AdaptyUI.ActionType.Close:
+ case AdaptyUIUserActionType.Close:
view.Dismiss(null);
break;
- case AdaptyUI.ActionType.OpenUrl:
+ case AdaptyUIUserActionType.OpenUrl:
var urlString = action.Value;
if (urlString != null {
Application.OpenURL(urlString);
}
default:
// handle other events
break;
}
} -
Update handling of started purchase:
- public void OnSelectProduct(
- AdaptyUI.View view,
- Adapty.PaywallProduct product
- ) { }
+ public void PaywallViewDidSelectProduct(
+ AdaptyUIView view,
+ string productId
+ ) { } -
Update handling of failed purchase:
- public void OnFailPurchase(
- AdaptyUI.View view,
- Adapty.PaywallProduct product,
- Adapty.Error error
- ) { }
+ public void PaywallViewDidFailPurchase(
+ AdaptyUIView view,
+ AdaptyPaywallProduct product,
+ AdaptyError error
+ ) { } -
Update handling of successful restore event:
- public void OnFailRestore(
- AdaptyUI.View view,
- Adapty.Error error
- ) { }
+ public void PaywallViewDidFailRestore(
+ AdaptyUIView view,
+ AdaptyError error
+ ) { }
Check out the final code example in the Handle paywall events page.
Update handling of Paywall Builder paywall errors
The handling of errors is changed as well, please update your code according to the guidance below.
-
Update the handling of the product loading errors:
- public void OnFailLoadingProducts(
- AdaptyUI.View view,
- Adapty.Error error
- ) { }
+ public void PaywallViewDidFailLoadingProducts(
+ AdaptyUIView view,
+ AdaptyError error
+ ) { } -
Update the handling of the rendering errors:
- public void OnFailRendering(
- AdaptyUI.View view,
- Adapty.Error error
- ) { }
+ public void PaywallViewDidFailRendering(
+ AdaptyUIView view,
+ AdaptyError error
+ ) { }
Update third-party integration SDK configuration
Starting with Adapty Unity SDK 3.3.0, we’ve updated the public API for the updateAttribution
method. Previously, it accepted a [AnyHashable: Any]
dictionary, allowing you to pass attribution objects directly from various services. Now, it requires a [String: any Sendable]
, so you’ll need to convert attribution objects before passing them.
To ensure integrations work properly with Adapty Unity SDK 3.3.0 and later, update your SDK configurations for the following integrations as described in the sections below.