Skip to content

Commit

Permalink
Merge branch 'SK2-clean' into develop
Browse files Browse the repository at this point in the history
* SK2-clean:
  Updated fetch viewConfiguration - parameters for Java, Kotlin & RN. Unity removed
  • Loading branch information
Lutik-sun committed Nov 20, 2024
2 parents 707ac6f + 1999cf4 commit 59d3583
Showing 1 changed file with 38 additions and 94 deletions.
132 changes: 38 additions & 94 deletions versioned_docs/version-3.0/get-pb-paywalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ To get a paywall, use the `getPaywall` method:

```swift
do {
let paywall = try await Adapty.getPaywall(placementId:"YOUR_PLACEMENT_ID")
let paywall = try await Adapty.getPaywall("YOUR_PLACEMENT_ID")
// the requested paywall
} catch {
// handle the error
}
```
</TabItem>
<TabItem value="Swift-Callback" label="Swift-Callback" default>
<TabItem value="Swift-Callback" label="Swift" default>

```swift
Adapty.getPaywall(placementId: "YOUR_PLACEMENT_ID", locale: "en") { result in
Expand Down Expand Up @@ -113,27 +113,14 @@ try {
}
```
</TabItem>
<TabItem value="Unity" label="Unity" default>

```csharp
Adapty.GetPaywall("YOUR_PLACEMENT_ID", "en", (paywall, error) => {
if(error != null) {
// handle the error
return;
}

// paywall - the resulting object
});
```
</TabItem>
<TabItem value="RN" label="React Native (TS)" default>

```typescript
try {
const id = 'YOUR_PLACEMENT_ID';
const placementId = 'YOUR_PLACEMENT_ID';
const locale = 'en';

const paywall = await adapty.getPaywall(id, locale);
const paywall = await adapty.getPaywall(placementId, locale);
// the requested paywall
} catch (error) {
// handle the error
Expand All @@ -142,6 +129,8 @@ try {
</TabItem>
</Tabs>

Parameters:

| Parameter | Presence | Description |
|---------|--------|-----------|
| **placementId** | required | The identifier of the desired [Placement](placements). This is the value you specified when creating a placement in the Adapty Dashboard. |
Expand Down Expand Up @@ -171,7 +160,6 @@ The result of the `createPaywallView` method can be used only once. If you need

<Tabs>
<TabItem value="Swift" label="Swift" default>

```swift
import Adapty

Expand All @@ -180,53 +168,24 @@ guard paywall.hasViewConfiguration else {
return
}

do {
let paywallConfiguration = try await AdaptyUI.getPaywallConfiguration(
forPaywall: paywall,
products: products,
observerModeResolver: <AdaptyObserverModeResolver>, // only for Observer Mode
tagResolver: <AdaptyTagResolver>,
timerResolver: <AdaptyTimerResolver>
)
// use loaded configuration
} catch {
// handle the error
AdaptyUI.getViewConfiguration(forPaywall: paywall) { result in
switch result {
case let .success(viewConfiguration):
// use loaded configuration
case let .failure(error):
// handle the error
}
}
```
Parameters:

| Parameter | Presence | Description |
| :----------------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | <p>This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.</p><p></p><p>Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood.</p> |
| **loadTimeout** | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood. |
| **products** | optional | Provide an array of `AdaptyPaywallProducts` to optimize the display timing of products on the screen. If `nil` is passed, AdaptyUI will automatically fetch the necessary products. |
| **observerModeResolver** | optional | The `AdaptyObserverModeResolver` object you've implemented in the previous step |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](custom-tags-in-paywall-builder) topic for more details. |
| **observerModeResolver** | optional | The `AdaptyObserverModeResolver` object you've implemented in the previous step |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](https://dev-docs.adapty.io/docs/custom-tags-in-paywall-builder) topic for more details. |
| **timerResolver** | optional | To use custom timers in your mobile app, create an object that follows the `AdaptyTimerResolver` protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a `[String: Date]` dictionary directly, as it already conforms to this protocol. |

## Use developer-defined timers

To use custom timers in your mobile app, create an object that conforms to the `AdaptyTimerResolver` protocol. This object should provide information about how to render each custom timer. Note that the `[String: Date]` structure already conforms to this protocol, so you can simply pass a dictionary. Here’s an example:

```Swift
@MainActor
struct AdaptyTimerResolverImpl: AdaptyTimerResolver {
func timerEndAtDate(for timerId: String) -> Date {
switch timerId {
case "CUSTOM_TIMER_6H":
Date(timeIntervalSinceNow: 3600.0 * 6.0) // 6 hours
case "CUSTOM_TIMER_NY":
Calendar.current.date(from: DateComponents(year: 2025, month: 1, day: 1)) ?? Date(timeIntervalSinceNow: 3600.0)
default:
Date(timeIntervalSinceNow: 3600.0) // 1 hour
}
}
}
```

- `CUSTOM_TIMER_NY`: The time remaining until the timer’s end, such as New Year’s Day.
- `CUSTOM_TIMER_6H`: The time left in a 6-hour period that started when the user opened the paywall.

</TabItem>
<TabItem value="kotlin" label="Kotlin" default>

Expand All @@ -236,7 +195,7 @@ if (!paywall.hasViewConfiguration) {
return
}

AdaptyUI.getViewConfiguration(paywall) { result ->
AdaptyUI.getViewConfiguration(paywall, loadTimeout = 10.seconds) { result ->
when(result) {
is AdaptyResult.Success -> {
val viewConfiguration = result.value
Expand All @@ -249,16 +208,10 @@ AdaptyUI.getViewConfiguration(paywall) { result ->
}
}
```
Parameters:

| Parameter | Presence | Description |
| :----------------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | <p>This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.</p><p></p><p>Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood.</p> |
| **products** | optional | Provide an array of `AdaptyPaywallProducts` to optimize the display timing of products on the screen. If `nil` is passed, AdaptyUI will automatically fetch the necessary products. |
| **observerModeResolver** | optional | The `AdaptyObserverModeResolver` object you've implemented in the previous step |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](custom-tags-in-paywall-builder) topic for more details. |
| **timerResolver** | optional | To use custom timers in your mobile app, create an object that follows the `AdaptyTimerResolver` protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a `[String: Date]` dictionary directly, as it already conforms to this protocol. |
| Parameter | Presence | Description |
| :-------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood. |

</TabItem>
<TabItem value="java" label="Java" default>
Expand All @@ -269,7 +222,7 @@ if (!paywall.hasViewConfiguration()) {
return;
}

AdaptyUI.getViewConfiguration(paywall, result -> {
AdaptyUI.getViewConfiguration(paywall, TimeInterval.seconds(10), result -> {
if (result instanceof AdaptyResult.Success) {
AdaptyUI.LocalizedViewConfiguration viewConfiguration =
((AdaptyResult.Success<AdaptyUI.LocalizedViewConfiguration>) result).getValue();
Expand All @@ -280,38 +233,31 @@ AdaptyUI.getViewConfiguration(paywall, result -> {
}
});
```
| Parameter | Presence | Description |
| :----------------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood. |

</TabItem>
<TabItem value="Flutter" label="Flutter" default>

```javascript
import 'package:adapty_flutter/adapty_flutter.dart';
import 'package:adapty_ui_flutter/adapty_ui_flutter.dart';

try {
final view = await AdaptyUI().createPaywallView(
paywall: paywall,
customTags: {
'CUSTOM_TAG_NAME': 'John',
},
customTimers: {
'CUSTOM_TIMER_6H': DateTime.now().add(const Duration(seconds: 3600 * 6)),
'CUSTOM_TIMER_NY': DateTime(2025, 1, 1), // New Year 2025
},
preloadProducts: preloadProducts,
);
final view = await AdaptyUI().createPaywallView(paywall: paywall);
} on AdaptyError catch (e) {
// handle the error
} catch (e) {
// handle the error
}
```
Parameters:
| Parameter | Presence | Description |
| :---------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | <p>This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.</p><p></p><p>Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood.</p> |
| **loadTimeout** | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood. |
| **products** | optional | Provide an array of `AdaptyPaywallProducts` to optimize the display timing of products on the screen. If `nil` is passed, AdaptyUI will automatically fetch the necessary products. |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](custom-tags-in-paywall-builder) topic for more details. |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](https://dev-docs.adapty.io/docs/custom-tags-in-paywall-builder) topic for more details. |
| **timerResolver** | optional | To use custom timers in your mobile app, create an object that follows the `AdaptyTimerResolver` protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a `[String: Date]` dictionary directly, as it already conforms to this protocol. |

In the example above, `CUSTOM_TIMER_NY` and `CUSTOM_TIMER_6H` are the **Timer ID**s of developer-defined timers you set in the Adapty Dashboard. The `timerResolver` ensures your app dynamically updates each timer with the correct value—for example:
Expand All @@ -337,13 +283,12 @@ if (paywall.hasViewConfiguration) {
```
Parameters:

| Parameter | Presence | Description |
| :---------------- | :------------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **loadTimeout** | default: 5 sec | <p>This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned.</p><p></p><p>Note that in rare cases this method can timeout slightly later than specified in `loadTimeout`, since the operation may consist of different requests under the hood.</p> |
| **products** | optional | Provide an array of `AdaptyPaywallProducts` to optimize the display timing of products on the screen. If `nil` is passed, AdaptyUI will automatically fetch the necessary products. |
| **tagResolver** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](custom-tags-in-paywall-builder) topic for more details. |
| **timerResolver** | optional | To use custom timers in your mobile app, create an object that follows the `AdaptyTimerResolver` protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a `[String: Date]` dictionary directly, as it already conforms to this protocol. |
| Parameter | Presence | Description |
| :------------------- | :------- | :----------------------------------------------------------- |
| **paywall** | required | An `AdaptyPaywall` object to obtain a controller for the desired paywall. |
| **customTags** | optional | Define a dictionary of custom tags and their resolved values. Custom tags serve as placeholders in the paywall content, dynamically replaced with specific strings for personalized content within the paywall. Refer to [Custom tags in paywall builder](custom-tags-in-paywall-builder) topic for more details. |
| **timerInfo** | optional | To use custom timers in your mobile app, create an object that follows the `AdaptyTimerResolver` protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a `[String: Date]` dictionary directly, as it already conforms to this protocol. |
| **prefetchProducts** | optional | Enable to optimize the display timing of products on the screen. When `true` AdaptyUI will automatically fetch the necessary products. Default: `false`. |

</TabItem>
</Tabs>
Expand All @@ -352,8 +297,7 @@ Parameters:
If you are using multiple languages, learn how to add a [Paywall builder localization](add-paywall-locale-in-adapty-paywall-builder) and how to use locale codes correctly [here](localizations-and-locale-codes).
:::

Once you have successfully loaded the paywall and its paywall configuration, you can proceed to presenting the paywall in your mobile app.
Once you have successfully loaded the paywall and its view configuration, you can proceed to presenting the paywall in your mobile app.

## Speed up paywall fetching with default audience paywall

Expand Down

0 comments on commit 59d3583

Please sign in to comment.