Skip to content

Commit

Permalink
add async-await version of getPaywallForDefaultAudience method
Browse files Browse the repository at this point in the history
  • Loading branch information
x401om committed Aug 15, 2024
1 parent 3479272 commit 979ae3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Sources/Adapty+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ import StoreKit
/// This parameter is expected to be a language code composed of one or more subtags separated by the "-" character. The first subtag is for the language, the second one is for the region (The support for regions will be added later).
/// Example: "en" means English, "en-US" represents US English.
/// If the parameter is omitted, the paywall will be returned in the default locale.
/// - fetchPolicy:
/// - fetchPolicy: by default SDK will try to load data from server and will return cached data in case of failure. Otherwise use `.returnCacheDataElseLoad` to return cached data if it exists.
/// - Returns: The ``AdaptyPaywall`` object. This model contains the list of the products ids, paywall's identifier, custom payload, and several other properties.
/// - Throws: An ``AdaptyError`` object
public static func getPaywall(
Expand All @@ -179,6 +179,34 @@ import StoreKit
}
}
}

/// This method enables you to retrieve the paywall from the Default Audience without having to wait for the Adapty SDK to send all the user information required for segmentation to the server.
///
/// - Parameters:
/// - placementId: The identifier of the desired paywall. This is the value you specified when you created the paywall in the Adapty Dashboard.
/// - locale: The identifier of the paywall [localization](https://docs.adapty.io/docs/paywall#localizations).
/// This parameter is expected to be a language code composed of one or more subtags separated by the "-" character. The first subtag is for the language, the second one is for the region (The support for regions will be added later).
/// Example: "en" means English, "en-US" represents US English.
/// If the parameter is omitted, the paywall will be returned in the default locale.
/// - fetchPolicy: by default SDK will try to load data from server and will return cached data in case of failure. Otherwise use `.returnCacheDataElseLoad` to return cached data if it exists.
/// - Returns: The ``AdaptyPaywall`` object. This model contains the list of the products ids, paywall's identifier, custom payload, and several other properties.
/// - Throws: An ``AdaptyError`` object
public static func getPaywallForDefaultAudience(
placementId: String,
locale: String? = nil,
fetchPolicy: AdaptyPaywall.FetchPolicy = .default
) async throws -> AdaptyPaywall {
return try await withCheckedThrowingContinuation { continuation in
Adapty.getPaywallForDefaultAudience(placementId: placementId, locale: locale, fetchPolicy: fetchPolicy) { result in
switch result {
case let .failure(error):
continuation.resume(throwing: error)
case let .success(paywall):
continuation.resume(returning: paywall)
}
}
}
}

/// Once you have a ``AdaptyPaywall``, fetch corresponding products array using this method.
///
Expand Down
10 changes: 10 additions & 0 deletions Sources/Adapty+UntargetedPaywalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
import Foundation

extension Adapty {
/// This method enables you to retrieve the paywall from the Default Audience without having to wait for the Adapty SDK to send all the user information required for segmentation to the server.
///
/// - Parameters:
/// - placementId: The identifier of the desired placement. This is the value you specified when you created the placement in the Adapty Dashboard.
/// - locale: The identifier of the paywall [localization](https://docs.adapty.io/docs/paywall#localizations).
/// This parameter is expected to be a language code composed of one or more subtags separated by the "-" character. The first subtag is for the language, the second one is for the region (The support for regions will be added later).
/// Example: "en" means English, "en-US" represents US English.
/// If the parameter is omitted, the paywall will be returned in the default locale.
/// - fetchPolicy:by default SDK will try to load data from server and will return cached data in case of failure. Otherwise use `.returnCacheDataElseLoad` to return cached data if it exists.
/// - completion: A result containing the ``AdaptyPaywall`` object. This model contains the list of the products ids, paywall's identifier, custom payload, and several other properties.
public static func getPaywallForDefaultAudience(
placementId: String,
locale: String? = nil,
Expand Down

0 comments on commit 979ae3d

Please sign in to comment.