Migrate Adapty iOS SDK to v4.5
To update your app from Adapty iOS SDK 4.4 to 4.5, apply every change in this guide. An app on 4.3 or earlier needs the v4.4 changes first.
In 4.5, getFlowConfiguration requires a list of languages in preferredLocales, instead of an optional locale code in locale. The SDK selects a localization of the flow from this list.
The build fails until every getFlowConfiguration call passes preferredLocales. After you fix the build, SDK 4.5 can show users a different localization of the same flow than SDK 4.4 did.
Quick reference
| Before | After |
|---|---|
getFlowConfiguration(forFlow: flow, locale: "fr") | getFlowConfiguration(forFlow: flow, preferredLocales: Locale.preferredLanguages) |
locale: optional | preferredLocales: required |
No locale: users see en, even when the default locale of the flow is another language. Without en in the flow, users see the default locale | preferredLocales: []: all users see the flow in its default locale, whatever their device languages |
| No strategy parameter | localizationStrategy:, optional. The default, .auto, fits most apps. |
Replace locale with the user’s languages
In 4.5, both getFlowConfiguration methods, async and completion-handler, take a preferredLocales list instead of locale. The preferredLocales parameter is required. For a call with locale or without either parameter, Xcode reports:
'getFlowConfiguration(forFlow:locale:…)' is unavailable: Pass preferredLocales: Locale.preferredLanguages to show the flow in the device's language, or [] to use the flow's default localization.
The locale parameter of getOnboarding doesn’t change.
let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
forFlow: flow,
- locale: "fr"
+ preferredLocales: Locale.preferredLanguages
)
What your app passed in 4.4 determines what to pass in 4.5:
- If your app passed a device value, such as
Locale.current.identifier, passLocale.preferredLanguagesinstead. Delete any code that converted the value: case and separators don’t matter in 4.5. - If your app passed a language that the user selected in the app, put it first:
[selectedLanguage] + Locale.preferredLanguages. When a flow from the Flow & Paywall Builder lacks that language, the SDK tries the device’s languages. - If your app called
getFlowConfigurationwithoutlocale, addpreferredLocales: Locale.preferredLanguages.
To show the flow in the language of the UI of your app instead of the device languages, pass Bundle.main.preferredLocalizations. To compare the two lists, read Pass the user’s languages to the SDK.
To show every user the flow in its default locale, pass an empty list: preferredLocales: [].
You don’t need to pass localizationStrategy. Its default, .auto, is suitable for flows from the Flow & Paywall Builder and for paywalls from the old Paywall Builder. The other strategies change how the SDK matches languages.
What users see after the update
With the default localizationStrategy, SDK 4.5 can show users a different localization of the same flow than SDK 4.4:
| The app passes | The flow has | 4.4 | 4.5 |
|---|---|---|---|
No languages: no locale in 4.4, [] in 4.5 | Any locales | en, if the flow has it; otherwise, the default locale | The default locale |
A code with another case or separator, such as pt_BR | pt-BR | The default locale | pt-BR |
A regional code, such as pt-BR | The language alone, such as pt | The default locale | pt |
A regional code that implies a script, such as zh-TW | The script, such as zh-hant | The default locale | zh-hant; on paywalls from the old Paywall Builder, the default locale |
Several languages, such as fr, then de | A later language, such as de, but not the first one | The default locale | The later language; on paywalls from the old Paywall Builder, the default locale |
App versions on SDK 4.0–4.4 keep exact matching against your flows until users update the app. The .legacy strategy doesn’t bring back the exact matching of 4.4.
To see which localization appears on a device, read flowConfiguration.locale: the SDK doesn’t log it. For a test procedure, read Test which localization a user sees.
Review the locales of your flows
SDK 4.5 displays your published flows with their current locales. To show users each flow in a language they read, follow three rules:
- Translate the default locale fully. Users see it when the flow has none of their languages. To view or change the default, read Set the default locale.
- For app versions on SDK 4.0–4.4 and apps on other Adapty SDKs, keep every locale code that they pass. Those apps don’t use the 4.5 matching.
- To cover more users, add the locales that 4.5 matches better, such as
zh-hansandzh-hantin addition tozh.
Add the AdaptyUIBuilder module
In 4.5, some types for AdaptyUI come from the AdaptyUIBuilder module, such as the protocol for a custom localization resolver. To use these types in your code, add AdaptyUIBuilder to your app:
- In Xcode, in the General tab of your app target, under Frameworks, Libraries, and Embedded Content, add AdaptyUIBuilder from the AdaptySDK-iOS package.
- In each file that uses these types, add
import AdaptyUIBuilder.