Skip to content

Commit d4b2690

Browse files
authored
Merge pull request #283 from superwall/v4-develop
4.0.0-beta.3
2 parents 492b396 + f528998 commit d4b2690

File tree

10 files changed

+59
-39
lines changed

10 files changed

+59
-39
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
The changelog for `SuperwallKit`. Also see the [releases](https://github.com/superwall/Superwall-iOS/releases) on GitHub.
44

5+
## 4.0.0-beta.3
6+
7+
### Breaking Changes
8+
9+
- Renames `PaywallView(event:)` to `PaywallView(placement:)`.
10+
11+
### Fixes
12+
13+
- Adds extra check to get StoreKit 2 transaction data on `transaction_complete`.
14+
515
## 4.0.0-beta.2
616

717
### Fixes
818

919
- Fixes an issue to do with audience filters.
10-
- Readds unavailable functions from v3 to make the upgrade path smoother.
20+
- Re-adds unavailable functions from v3 to make the upgrade path smoother.
1121

1222
## 4.0.0-beta.1
1323

Sources/SuperwallKit/Config/Options/SuperwallOptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public final class SuperwallOptions: NSObject, Encodable {
189189
/// failure before it times out. Defaults to 6.
190190
///
191191
/// Adjust this if you want the SDK to call the ``PaywallPresentationHandler/onError(_:)``
192-
/// handler of the ``PaywallPresentationHandler`` faster when you call ``Superwall/register(event:)``
192+
/// handler of the ``PaywallPresentationHandler`` faster when you call ``Superwall/register(placement:)``
193193
public var maxConfigRetryCount = 6 {
194194
didSet {
195195
// Must be >= 0

Sources/SuperwallKit/Documentation.docc/Extensions/SuperwallExtension.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The `Superwall` class is used to access all the features of the SDK. Before usin
5959
- `PaywallViewController`
6060
- `PaywallViewControllerDelegate`
6161
- `PaywallViewControllerDelegateObjc`
62+
- `PaywallView`
6263

6364
### Handling Purchases
6465

Sources/SuperwallKit/Paywall/Presentation/Audience Logic/Expression Evaluator/EvaluationContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func toPassableValue(from anyValue: Any) -> PassableValue {
7878
if let number = anyValue as? NSNumber {
7979
// Check if it is a boolean
8080
if CFGetTypeID(number) == CFBooleanGetTypeID() {
81-
return .bool(number.boolValue)
81+
return .bool(number.boolValue)
8282
}
8383
// If not a boolean, let the switch handle the rest
8484
}

Sources/SuperwallKit/Paywall/Presentation/Get Paywall/SwiftUI/PaywallView.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
/// A SwiftUI paywall view that you can embed into your app.
1111
///
12-
/// This uses ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)`` under the hood.
12+
/// This uses ``Superwall/getPaywall(forPlacement:params:paywallOverrides:delegate:)`` under the hood.
1313
///
1414
/// - Warning: You're responsible for the deallocation of this view. If you have a `PaywallView` presented somewhere
1515
/// and you try to present the same `PaywallView` elsewhere, you will get a crash.
@@ -21,10 +21,10 @@ public struct PaywallView<
2121
@State private var hasLoaded = false
2222
@Environment(\.presentationMode) private var presentationMode
2323

24-
/// The name of the event, as you have defined on the Superwall dashboard.
25-
private let event: String
24+
/// The name of the placement, as you have defined on the Superwall dashboard.
25+
private let placement: String
2626

27-
/// Optional parameters you'd like to pass with your event. Defaults to `nil`.
27+
/// Optional parameters you'd like to pass with your placement. Defaults to `nil`.
2828
///
2929
/// These can be referenced within the rules
3030
/// of your campaign. Keys beginning with `$` are reserved for Superwall and will be dropped. Values can be any
@@ -60,11 +60,11 @@ public struct PaywallView<
6060

6161
/// A SwiftUI paywall view that you can embed into your app.
6262
///
63-
/// This uses ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)`` under the hood.
63+
/// This uses ``Superwall/getPaywall(forPlacement:params:paywallOverrides:delegate:)`` under the hood.
6464
///
6565
/// - Parameters:
66-
/// - event: The name of the event, as you have defined on the Superwall dashboard.
67-
/// - params: Optional parameters you'd like to pass with your event. These can be referenced within the rules
66+
/// - placement: The name of the placement, as you have defined on the Superwall dashboard.
67+
/// - params: Optional parameters you'd like to pass with your placement. These can be referenced within the rules
6868
/// of your campaign. Keys beginning with `$` are reserved for Superwall and will be dropped. Values can be any
6969
/// JSON encodable value, URLs or Dates. Arrays and dictionaries as values are not supported at this time, and will
7070
/// be dropped.
@@ -84,15 +84,15 @@ public struct PaywallView<
8484
/// - Warning: You're responsible for the deallocation of this view. If you have a `PaywallView` presented somewhere
8585
/// and you try to present the same `PaywallView` elsewhere, you will get a crash.
8686
public init(
87-
event: String,
87+
placement: String,
8888
params: [String: Any]? = nil,
8989
paywallOverrides: PaywallOverrides? = nil,
9090
onRequestDismiss: ((PaywallInfo, PaywallResult) -> Void)? = nil,
9191
onSkippedView: ((PaywallSkippedReason) -> OnSkippedView)? = nil,
9292
onErrorView: ((Error) -> OnErrorView)? = nil,
9393
feature: (() -> Void)? = nil
9494
) {
95-
self.event = event
95+
self.placement = placement
9696
self.params = params
9797
self.paywallOverrides = paywallOverrides
9898
self.onRequestDismiss = onRequestDismiss
@@ -140,7 +140,7 @@ public struct PaywallView<
140140
hasLoaded = true
141141
Task {
142142
await manager.getPaywall(
143-
forPlacement: event,
143+
forPlacement: placement,
144144
params: params,
145145
paywallOverrides: paywallOverrides
146146
)
@@ -154,10 +154,10 @@ public struct PaywallView<
154154
extension PaywallView where OnSkippedView == Never, OnErrorView == Never {
155155
/// A SwiftUI paywall view that you can embed into your app.
156156
///
157-
/// This uses ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)`` under the hood.
157+
/// This uses ``Superwall/getPaywall(forPlacement:params:paywallOverrides:delegate:)`` under the hood.
158158
///
159159
/// - Parameters:
160-
/// - event: The name of the event, as you have defined on the Superwall dashboard.
160+
/// - placement: The name of the placement, as you have defined on the Superwall dashboard.
161161
/// - params: Optional parameters you'd like to pass with your event. These can be referenced within the rules
162162
/// of your campaign. Keys beginning with `$` are reserved for Superwall and will be dropped. Values can be any
163163
/// JSON encodable value, URLs or Dates. Arrays and dictionaries as values are not supported at this time, and will
@@ -174,13 +174,13 @@ extension PaywallView where OnSkippedView == Never, OnErrorView == Never {
174174
/// - Warning: You're responsible for the deallocation of this view. If you have a `PaywallView` presented somewhere
175175
/// and you try to present the same `PaywallView` elsewhere, you will get a crash.
176176
public init(
177-
event: String,
177+
placement: String,
178178
params: [String: Any]? = nil,
179179
paywallOverrides: PaywallOverrides? = nil,
180180
onRequestDismiss: ((PaywallInfo, PaywallResult) -> Void)? = nil,
181181
feature: (() -> Void)? = nil
182182
) {
183-
self.event = event
183+
self.placement = placement
184184
self.params = params
185185
self.paywallOverrides = paywallOverrides
186186
self.onErrorView = nil
@@ -194,11 +194,11 @@ extension PaywallView where OnSkippedView == Never, OnErrorView == Never {
194194
extension PaywallView where OnSkippedView == Never {
195195
/// A SwiftUI paywall view that you can embed into your app.
196196
///
197-
/// This uses ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)`` under the hood.
197+
/// This uses ``Superwall/getPaywall(forPlacement:params:paywallOverrides:delegate:)`` under the hood.
198198
///
199199
/// - Parameters:
200-
/// - event: The name of the event, as you have defined on the Superwall dashboard.
201-
/// - params: Optional parameters you'd like to pass with your event. These can be referenced within the rules
200+
/// - placement: The name of the placement, as you have defined on the Superwall dashboard.
201+
/// - params: Optional parameters you'd like to pass with your placement. These can be referenced within the rules
202202
/// of your campaign. Keys beginning with `$` are reserved for Superwall and will be dropped. Values can be any
203203
/// JSON encodable value, URLs or Dates. Arrays and dictionaries as values are not supported at this time, and will
204204
/// be dropped.
@@ -216,14 +216,14 @@ extension PaywallView where OnSkippedView == Never {
216216
/// - Warning: You're responsible for the deallocation of this view. If you have a `PaywallView` presented somewhere
217217
/// and you try to present the same `PaywallView` elsewhere, you will get a crash.
218218
public init(
219-
event: String,
219+
placement: String,
220220
params: [String: Any]? = nil,
221221
paywallOverrides: PaywallOverrides? = nil,
222222
onRequestDismiss: ((PaywallInfo, PaywallResult) -> Void)? = nil,
223223
onErrorView: @escaping (Error) -> OnErrorView,
224224
feature: (() -> Void)? = nil
225225
) {
226-
self.event = event
226+
self.placement = placement
227227
self.params = params
228228
self.paywallOverrides = paywallOverrides
229229
self.onRequestDismiss = onRequestDismiss
@@ -237,11 +237,11 @@ extension PaywallView where OnSkippedView == Never {
237237
extension PaywallView where OnErrorView == Never {
238238
/// A SwiftUI paywall view that you can embed into your app.
239239
///
240-
/// This uses ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)`` under the hood.
240+
/// This uses ``Superwall/getPaywall(forPlacement:params:paywallOverrides:delegate:)`` under the hood.
241241
///
242242
/// - Parameters:
243-
/// - event: The name of the event, as you have defined on the Superwall dashboard.
244-
/// - params: Optional parameters you'd like to pass with your event. These can be referenced within the rules
243+
/// - placement: The name of the placement, as you have defined on the Superwall dashboard.
244+
/// - params: Optional parameters you'd like to pass with your placement. These can be referenced within the rules
245245
/// of your campaign. Keys beginning with `$` are reserved for Superwall and will be dropped. Values can be any
246246
/// JSON encodable value, URLs or Dates. Arrays and dictionaries as values are not supported at this time, and will
247247
/// be dropped.
@@ -261,14 +261,14 @@ extension PaywallView where OnErrorView == Never {
261261
/// - Warning: You're responsible for the deallocation of this view. If you have a `PaywallView` presented somewhere
262262
/// and you try to present the same `PaywallView` elsewhere, you will get a crash.
263263
public init(
264-
event: String,
264+
placement: String,
265265
params: [String: Any]? = nil,
266266
paywallOverrides: PaywallOverrides? = nil,
267267
onRequestDismiss: ((PaywallInfo, PaywallResult) -> Void)? = nil,
268268
onSkippedView: @escaping (PaywallSkippedReason) -> OnSkippedView,
269269
feature: (() -> Void)? = nil
270270
) {
271-
self.event = event
271+
self.placement = placement
272272
self.params = params
273273
self.paywallOverrides = paywallOverrides
274274
self.onErrorView = nil

Sources/SuperwallKit/StoreKit/Transactions/Purchasing/PurchaseManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ final class PurchaseManager: Purchasing {
5555
identityManager: identityManager,
5656
receiptManager: receiptManager,
5757
storage: storage,
58+
coordinator: coordinator,
5859
factory: factory
5960
)
6061
_sk2TransactionListener = SK2TransactionListener(

Sources/SuperwallKit/StoreKit/Transactions/Purchasing/PurchasingCoordinator.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,21 @@ actor PurchasingCoordinator {
137137
result: PurchaseResult
138138
) async {
139139
let transaction = await factory.makeStoreTransaction(from: transaction)
140-
completePurchase(of: transaction, result: result)
140+
storeTransaction(transaction, result: result)
141+
completion?(result)
141142
}
142143

143144
@available(iOS 15.0, *)
144-
func completePurchase(
145-
of transaction: SK2Transaction,
145+
func storeTransaction(
146+
_ transaction: SK2Transaction,
146147
result: PurchaseResult
147148
) async {
148149
let transaction = await factory.makeStoreTransaction(from: transaction)
149-
completePurchase(of: transaction, result: result)
150+
storeTransaction(transaction, result: result)
150151
}
151152

152-
private func completePurchase(
153-
of transaction: StoreTransaction,
153+
private func storeTransaction(
154+
_ transaction: StoreTransaction,
154155
result: PurchaseResult
155156
) {
156157
if result == .purchased {
@@ -170,7 +171,6 @@ actor PurchasingCoordinator {
170171
}
171172
}
172173
lastInternalTransaction = transaction
173-
completion?(result)
174174
}
175175

176176
func reset() {

Sources/SuperwallKit/StoreKit/Transactions/Purchasing/StoreKit 1/ProductPurchaserSK1.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ extension ProductPurchaserSK1: SKPaymentTransactionObserver {
209209
)
210210
if !isExistingTransaction {
211211
let transactionManager = factory.makeTransactionManager()
212-
await transactionManager.observeTransaction(for: skTransaction.payment.productIdentifier)
212+
await transactionManager.observeSK1Transaction(for: skTransaction.payment.productIdentifier)
213213
storedIds.insert(skTransaction.payment.productIdentifier)
214214
storage.save(storedIds, forType: PurchasingProductIds.self)
215215
}
@@ -262,7 +262,8 @@ extension ProductPurchaserSK1: SKPaymentTransactionObserver {
262262
}
263263
await coordinator.completePurchase(
264264
of: skTransaction,
265-
result: .failed(error))
265+
result: .failed(error)
266+
)
266267
}
267268
case .deferred:
268269
finishTransaction(skTransaction)

Sources/SuperwallKit/StoreKit/Transactions/Purchasing/StoreKit 2/ProductPurchaserSK2.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import StoreKit
1212
final class ProductPurchaserSK2: Purchasing {
1313
private unowned let identityManager: IdentityManager
1414
private unowned let receiptManager: ReceiptManager
15+
private let coordinator: PurchasingCoordinator
1516
private unowned let factory: Factory
1617
typealias Factory = HasExternalPurchaseControllerFactory
1718
& OptionsFactory
@@ -30,10 +31,12 @@ final class ProductPurchaserSK2: Purchasing {
3031
identityManager: IdentityManager,
3132
receiptManager: ReceiptManager,
3233
storage: Storage,
34+
coordinator: PurchasingCoordinator,
3335
factory: Factory
3436
) {
3537
self.identityManager = identityManager
3638
self.receiptManager = receiptManager
39+
self.coordinator = coordinator
3740
self.factory = factory
3841

3942
if #available(iOS 17.2, *) {
@@ -105,10 +108,14 @@ final class ProductPurchaserSK2: Purchasing {
105108
case let .success(.verified(transaction)):
106109
await transaction.finish()
107110
await receiptManager.loadPurchasedProducts()
108-
return .purchased
111+
let result = PurchaseResult.purchased
112+
await coordinator.storeTransaction(transaction, result: result)
113+
return result
109114
case let .success(.unverified(transaction, error)):
110115
await transaction.finish()
111-
return .failed(error)
116+
let result = PurchaseResult.failed(error)
117+
await coordinator.storeTransaction(transaction, result: result)
118+
return result
112119
case .userCancelled:
113120
return .cancelled
114121
case .pending:

Sources/SuperwallKit/StoreKit/Transactions/TransactionManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ final class TransactionManager {
453453
}
454454
}
455455

456-
func observeTransaction(for productId: String) async {
456+
func observeSK1Transaction(for productId: String) async {
457457
guard
458458
let storeProduct = try? await productsManager.products(
459459
identifiers: [productId],

0 commit comments

Comments
 (0)