Skip to content

Commit 566713b

Browse files
authored
Merge pull request #419 from superwall/develop
4.12.6
2 parents 583f512 + e26bcf5 commit 566713b

File tree

17 files changed

+497
-154
lines changed

17 files changed

+497
-154
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## 4.12.6
6+
7+
### Enhancements
8+
9+
- Adds post purchase actions support.
10+
11+
### Fixes
12+
13+
- Fixes a rare issue where TestFlight products could display in a different currency on the paywall than on Apple's payment sheet.
14+
515
## 4.12.5
616

717
### Enhancements

Examples/Advanced/Advanced.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SuperwallKit/Logger/Logger.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ enum Logger: Loggable {
105105
dumping["error"] = error
106106
}
107107

108-
var name = "\(Date().isoString) \(logLevel.descriptionEmoji) [Superwall] [\(scope.description)] - \(logLevel.description)"
108+
var name = "\(Date().isoString) \(logLevel.descriptionEmoji) "
109+
+ "[Superwall] [\(scope.description)] - \(logLevel.description)"
109110

110111
if let message = message {
111112
name += ": \(message)"

Sources/SuperwallKit/Misc/Constants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ let sdkVersion = """
1818
*/
1919

2020
let sdkVersion = """
21-
4.12.5
21+
4.12.6
2222
"""

Sources/SuperwallKit/Paywall/View Controller/Web View/Message Handling/PaywallMessage.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ enum PaywallMessage: Decodable, Equatable {
5151
case openUrlInSafari(_ url: URL)
5252
case openPaymentSheet(_ url: URL)
5353
case openDeepLink(url: URL)
54-
case purchase(productId: String)
54+
case purchase(productId: String, shouldDismiss: Bool)
5555
case custom(data: String)
5656
case customPlacement(name: String, params: JSON)
5757
case userAttributesUpdated(attributes: JSON)
@@ -101,9 +101,11 @@ enum PaywallMessage: Decodable, Equatable {
101101
}
102102

103103
// Everyone write to eventName, other may use the remaining keys
104+
// Note: JSONDecoder.fromSnakeCase converts snake_case keys to camelCase automatically
104105
private enum CodingKeys: String, CodingKey {
105106
case messageType = "eventName"
106107
case productId = "productIdentifier"
108+
case shouldDismiss
107109
case url
108110
case link
109111
case data
@@ -141,7 +143,8 @@ enum PaywallMessage: Decodable, Equatable {
141143
return
142144
case .purchase:
143145
if let productId = try? values.decode(String.self, forKey: .productId) {
144-
self = .purchase(productId: productId)
146+
let shouldDismiss = try values.decodeIfPresent(Bool.self, forKey: .shouldDismiss) ?? true
147+
self = .purchase(productId: productId, shouldDismiss: shouldDismiss)
145148
return
146149
}
147150
case .restore:

Sources/SuperwallKit/Paywall/View Controller/Web View/Message Handling/PaywallMessageHandler.swift

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,25 @@ final class PaywallMessageHandler: WebEventDelegate {
126126
await self.pass(placement: transactionStart, from: paywall)
127127
}
128128
case let .transactionComplete(trialEndDate, productIdentifier):
129-
let freeTrialStart = SuperwallEventObjc.freeTrialStart.description
130129
Task {
131-
var payload: [String: Any] = ["product_identifier": productIdentifier]
130+
// Send transaction_complete to trigger post-purchase actions
131+
let transactionComplete = SuperwallEventObjc.transactionComplete.description
132+
await self.pass(
133+
placement: transactionComplete,
134+
from: paywall,
135+
payload: ["product_identifier": productIdentifier]
136+
)
137+
138+
// Send freeTrial_start for notification scheduling
139+
let freeTrialStart = SuperwallEventObjc.freeTrialStart.description
140+
var freeTrialPayload: [String: Any] = ["product_identifier": productIdentifier]
132141
if let trialEndDate {
133-
payload["trial_end_date"] = Int(trialEndDate.timeIntervalSince1970 * 1000)
142+
freeTrialPayload["trial_end_date"] = Int(trialEndDate.timeIntervalSince1970 * 1000)
134143
}
135144
await self.pass(
136145
placement: freeTrialStart,
137146
from: paywall,
138-
payload: payload
147+
payload: freeTrialPayload
139148
)
140149
}
141150
case .transactionFail:
@@ -163,8 +172,8 @@ final class PaywallMessageHandler: WebEventDelegate {
163172
openDeepLink(url)
164173
case .restore:
165174
restorePurchases()
166-
case .purchase(productId: let id):
167-
purchaseProduct(withId: id)
175+
case let .purchase(productId: id, shouldDismiss: shouldDismiss):
176+
purchaseProduct(withId: id, shouldDismiss: shouldDismiss)
168177
case .custom(data: let name):
169178
handleCustomEvent(name)
170179
case let .customPlacement(name: name, params: params):
@@ -342,6 +351,7 @@ final class PaywallMessageHandler: WebEventDelegate {
342351

343352
// block selection
344353
let selectionString =
354+
// swiftlint:disable:next line_length
345355
"var css = '*{-webkit-touch-callout:none;-webkit-user-select:none} .w-webflow-badge { display: none !important; }'; "
346356
+ "var head = document.head || document.getElementsByTagName('head')[0]; "
347357
+ "var style = document.createElement('style'); style.type = 'text/css'; "
@@ -355,6 +365,7 @@ final class PaywallMessageHandler: WebEventDelegate {
355365
self.delegate?.webView.configuration.userContentController.addUserScript(selectionScript)
356366

357367
let preventSelection =
368+
// swiftlint:disable:next line_length
358369
"var css = '*{-webkit-touch-callout:none;-webkit-user-select:none}'; var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; style.appendChild(document.createTextNode(css)); head.appendChild(style);"
359370
self.delegate?.webView.evaluateJavaScript(preventSelection)
360371

@@ -431,10 +442,18 @@ final class PaywallMessageHandler: WebEventDelegate {
431442
delegate?.eventDidOccur(.initiateRestore)
432443
}
433444

434-
private func purchaseProduct(withId id: String) {
445+
private func purchaseProduct(
446+
withId id: String,
447+
shouldDismiss: Bool
448+
) {
435449
detectHiddenPaywallEvent("purchase")
436450
hapticFeedback()
437-
delegate?.eventDidOccur(.initiatePurchase(productId: id))
451+
delegate?.eventDidOccur(
452+
.initiatePurchase(
453+
productId: id,
454+
shouldDismiss: shouldDismiss
455+
)
456+
)
438457
}
439458

440459
private func handleCustomEvent(_ customEvent: String) {

Sources/SuperwallKit/Paywall/View Controller/Web View/Message Handling/PaywallWebEvent.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import Foundation
99

1010
enum PaywallWebEvent: Equatable {
1111
case closed
12-
case initiatePurchase(productId: String)
12+
case initiatePurchase(
13+
productId: String,
14+
shouldDismiss: Bool
15+
)
1316
case initiateRestore
1417
case custom(string: String)
1518
case openedURL(url: URL)

Sources/SuperwallKit/Storage/Cache/Cache.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,23 @@ class Cache {
7171
guard let self = self else { return }
7272
guard
7373
let documentDirectory = self.fileManager.urls(for: .documentDirectory, in: .userDomainMask).first,
74-
let applicationSupportDirectory = self.fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
74+
let applicationSupportDirectory = self.fileManager.urls(
75+
for: .applicationSupportDirectory,
76+
in: .userDomainMask
77+
).first
7578
else {
7679
return
7780
}
7881

79-
let userSpecificDocumentUrl = documentDirectory.appendingPathComponent(Cache.userSpecificDocumentDirectoryPrefix)
80-
let appSpecificDocumentUrl = documentDirectory.appendingPathComponent(Cache.appSpecificDocumentDirectoryPrefix)
82+
let userSpecificDocumentUrl = documentDirectory
83+
.appendingPathComponent(Cache.userSpecificDocumentDirectoryPrefix)
84+
let appSpecificDocumentUrl = documentDirectory
85+
.appendingPathComponent(Cache.appSpecificDocumentDirectoryPrefix)
8186

82-
let userSpecificSupportUrl = applicationSupportDirectory.appendingPathComponent(Cache.userSpecificDocumentDirectoryPrefix)
83-
let appSpecificSupportUrl = applicationSupportDirectory.appendingPathComponent(Cache.appSpecificDocumentDirectoryPrefix)
87+
let userSpecificSupportUrl = applicationSupportDirectory
88+
.appendingPathComponent(Cache.userSpecificDocumentDirectoryPrefix)
89+
let appSpecificSupportUrl = applicationSupportDirectory
90+
.appendingPathComponent(Cache.appSpecificDocumentDirectoryPrefix)
8491

8592
do {
8693
// Create the destination directories if they don't exist.

0 commit comments

Comments
 (0)