Skip to content

Commit

Permalink
Merge pull request #218 from superwall/develop
Browse files Browse the repository at this point in the history
3.6.6
  • Loading branch information
yusuftor committed Jun 12, 2024
2 parents 99d89e2 + 8a037f3 commit abbbfaa
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 66 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

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

## 3.6.6

### Enhancements

- SW-2804: Exposes a `presentation` property on the `PaywallInfo` object. This contains information about the presentation of the paywall.
- Adds `restore_start`, `restore_complete`, and `restore_fail` events.
- SW-2850: Adds error message to `paywallWebviewLoad_fail`.
- SW-2851: Adds error message to `paywallProductsLoad_fail`.
- SW-2783: Logs error when trying to purchase a product that has failed to load.

### Fixes

- Makes sure the formatting of SK2 product variables use the same locale as the product.

## 3.6.5

### Enhancements

- Adds `enable_webview_process_pool`, `enable_suppresses_incremental_rendering`, `enable_throttle_scheduling_policy`, `enable_none_scheduling_policy` as feature flags for the webview configuration.
- Adds `enable_webview_process_pool`, `enable_suppresses_incremental_rendering`, `enable_throttle_scheduling_policy`, `enable_none_scheduling_policy` as feature flags for the webview configuration.

## 3.6.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,37 @@ enum InternalSuperwallEvent {
}
}

struct Restore: TrackableSuperwallEvent {
enum State {
case start
case fail(String)
case complete
}
let state: State
let paywallInfo: PaywallInfo

var superwallEvent: SuperwallEvent {
switch state {
case .start:
return .restoreStart
case .fail(let message):
return .restoreFail(message: message)
case .complete:
return .restoreComplete
}
}
var customParameters: [String: Any] {
return paywallInfo.customParams()
}
func getSuperwallParameters() async -> [String: Any] {
var eventParams = await paywallInfo.eventParams()
if case .fail(let message) = state {
eventParams["error_message"] = message
}
return eventParams
}
}

struct Transaction: TrackableSuperwallEvent {
enum State {
case start(StoreProduct)
Expand Down Expand Up @@ -550,7 +581,7 @@ enum InternalSuperwallEvent {
struct PaywallWebviewLoad: TrackableSuperwallEvent {
enum State {
case start
case fail
case fail(Error)
case timeout
case complete
}
Expand All @@ -571,7 +602,11 @@ enum InternalSuperwallEvent {
let paywallInfo: PaywallInfo

func getSuperwallParameters() async -> [String: Any] {
return await paywallInfo.eventParams()
var eventParams = await paywallInfo.eventParams()
if case .fail(let error) = state {
eventParams["error_message"] = error.safeLocalizedDescription
}
return eventParams
}
var customParameters: [String: Any] {
return paywallInfo.customParams()
Expand All @@ -581,7 +616,7 @@ enum InternalSuperwallEvent {
struct PaywallProductsLoad: TrackableSuperwallEvent {
enum State {
case start
case fail
case fail(Error)
case complete
}
let state: State
Expand All @@ -607,6 +642,9 @@ enum InternalSuperwallEvent {
var params: [String: Any] = [
"is_triggered_from_event": fromEvent
]
if case .fail(let error) = state {
params["error_message"] = error.safeLocalizedDescription
}
params += await paywallInfo.eventParams()
return params
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ public enum SuperwallEvent {
/// When ``Superwall/reset()`` is called.
case reset

/// When a restore is initiated
case restoreStart

/// When a restore fails.
case restoreFail(message: String)

/// When a restore completes.
case restoreComplete

var canImplicitlyTriggerPaywall: Bool {
switch self {
case .appInstall,
Expand Down Expand Up @@ -275,6 +284,12 @@ extension SuperwallEvent {
return .init(objcEvent: .surveyClose)
case .reset:
return .init(objcEvent: .reset)
case .restoreStart:
return .init(objcEvent: .restoreStart)
case .restoreFail:
return .init(objcEvent: .restoreFail)
case .restoreComplete:
return .init(objcEvent: .restoreComplete)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ public enum SuperwallEventObjc: Int, CaseIterable {
/// When ``Superwall/reset()`` is called.
case reset

/// When a restore is initiated.
case restoreStart

/// When a restore fails.
case restoreFail

/// When a restore completes.
case restoreComplete

public init(event: SuperwallEvent) {
self = event.backingData.objcEvent
}
Expand Down Expand Up @@ -228,6 +237,12 @@ public enum SuperwallEventObjc: Int, CaseIterable {
return "survey_close"
case .reset:
return "reset"
case .restoreStart:
return "restore_start"
case .restoreFail:
return "restore_fail"
case .restoreComplete:
return "restore_complete"
}
}
}
2 changes: 1 addition & 1 deletion Sources/SuperwallKit/Misc/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ let sdkVersion = """
*/

let sdkVersion = """
3.6.5
3.6.6
"""
26 changes: 6 additions & 20 deletions Sources/SuperwallKit/Models/Paywall/Paywall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,7 @@ struct Paywall: Decodable {
/// by the webview.
let htmlSubstitutions: String

struct Presentation {
var style: PaywallPresentationStyle = .modal
let condition: PresentationCondition
let delay: Int

init(
style: PaywallPresentationStyle,
condition: PresentationCondition,
delay: Int
) {
self.style = style
self.condition = condition
self.delay = delay
}
}
let presentation: Presentation
let presentation: PaywallPresentationInfo

let darkBackgroundColorHex: String?
let darkBackgroundColor: UIColor?
Expand Down Expand Up @@ -180,7 +165,7 @@ struct Paywall: Decodable {
let presentationCondition = try values.decode(PresentationCondition.self, forKey: .presentationCondition)
let presentationDelay = try values.decode(Int.self, forKey: .presentationDelay)

presentation = Presentation(
presentation = PaywallPresentationInfo(
style: presentationStyle,
condition: presentationCondition,
delay: presentationDelay
Expand Down Expand Up @@ -284,7 +269,7 @@ struct Paywall: Decodable {
triggerSessionId: String? = nil,
url: URL,
htmlSubstitutions: String,
presentation: Paywall.Presentation,
presentation: PaywallPresentationInfo,
backgroundColorHex: String,
backgroundColor: UIColor,
darkBackgroundColorHex: String?,
Expand Down Expand Up @@ -369,7 +354,8 @@ struct Paywall: Decodable {
closeReason: closeReason,
localNotifications: localNotifications,
computedPropertyRequests: computedPropertyRequests,
surveys: surveys
surveys: surveys,
presentation: presentation
)
}

Expand Down Expand Up @@ -403,7 +389,7 @@ extension Paywall: Stubbable {
name: "abc",
url: URL(string: "https://google.com")!,
htmlSubstitutions: "",
presentation: Presentation(
presentation: PaywallPresentationInfo(
style: .modal,
condition: .checkUserSubscription,
delay: 0
Expand Down
33 changes: 33 additions & 0 deletions Sources/SuperwallKit/Models/Paywall/PaywallPresentationInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// File.swift
//
//
// Created by Yusuf Tör on 03/06/2024.
//

import Foundation

/// Information about the presentation of the paywall.
@objc(SWKPaywallPresentationInfo)
@objcMembers
public final class PaywallPresentationInfo: NSObject {
/// The presentation style of the paywall.
public let style: PaywallPresentationStyle

/// The condition for when a paywall should present.
public let condition: PresentationCondition

/// The delay in milliseconds before switching from the loading view to
/// the paywall view.
public let delay: Int

init(
style: PaywallPresentationStyle = .modal,
condition: PresentationCondition,
delay: Int
) {
self.style = style
self.condition = condition
self.delay = delay
}
}
30 changes: 24 additions & 6 deletions Sources/SuperwallKit/Models/Paywall/PresentationCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@

import Foundation

enum PresentationCondition: String, Decodable {
case always = "ALWAYS"
case checkUserSubscription = "CHECK_USER_SUBSCRIPTION"
/// The condition for when a paywall should present.
@objc(SWKPresentationCondition)
public enum PresentationCondition: Int, Decodable {
/// The paywall will always present, regardless of subscription status.
case always

init(from decoder: Decoder) throws {
/// The paywall will only present if the ``Superwall/subscriptionStatus`` is ``SubscriptionStatus/inactive``.
case checkUserSubscription

enum CodingKeys: String, CodingKey {
case always = "ALWAYS"
case checkUserSubscription = "CHECK_USER_SUBSCRIPTION"
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(RawValue.self)
self = PresentationCondition(rawValue: rawValue) ?? .checkUserSubscription
let rawValue = try container.decode(String.self)
let type = CodingKeys(rawValue: rawValue)
switch type {
case .always:
self = .always
case .checkUserSubscription:
self = .checkUserSubscription
case nil:
self = .checkUserSubscription
}
}
}
29 changes: 19 additions & 10 deletions Sources/SuperwallKit/Network/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,11 @@ class Network {
}
}

@MainActor
func getConfig(
injectedApplicationStatePublisher: (AnyPublisher<UIApplication.State, Never>)? = nil,
isRetryingCallback: @escaping () -> Void
) async throws -> Config {
let existingApplicationStatePublisher = self.applicationStateSubject.eraseToAnyPublisher()
let applicationStatePublisher = injectedApplicationStatePublisher ?? existingApplicationStatePublisher

// Suspend until app is in foreground.
try await applicationStatePublisher
.subscribe(on: DispatchQueue.main)
.filter { $0 != .background }
.throwableAsync()
try await appInForeground(injectedApplicationStatePublisher)

do {
let requestId = UUID().uuidString
Expand All @@ -156,8 +148,25 @@ class Network {
}
}

func getGeoInfo() async -> GeoInfo? {
@MainActor
private func appInForeground(
_ injectedApplicationStatePublisher: (AnyPublisher<UIApplication.State, Never>)? = nil
) async throws {
let existingApplicationStatePublisher = self.applicationStateSubject.eraseToAnyPublisher()
let applicationStatePublisher = injectedApplicationStatePublisher ?? existingApplicationStatePublisher

// Suspend until app is in foreground.
try await applicationStatePublisher
.subscribe(on: DispatchQueue.main)
.filter { $0 != .background }
.throwableAsync()
}

func getGeoInfo(
injectedApplicationStatePublisher: (AnyPublisher<UIApplication.State, Never>)? = nil
) async -> GeoInfo? {
do {
try await appInForeground(injectedApplicationStatePublisher)
let geoWrapper = try await urlSession.request(.geo(factory: factory))
return geoWrapper.info
} catch {
Expand Down
14 changes: 12 additions & 2 deletions Sources/SuperwallKit/Paywall/Presentation/PaywallInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public final class PaywallInfo: NSObject {
/// Surveys attached to a paywall.
public let surveys: [Survey]

/// Information about the presentation of the paywall.
public let presentation: PaywallPresentationInfo

private unowned let factory: TriggerSessionManagerFactory

init(
Expand Down Expand Up @@ -151,7 +154,8 @@ public final class PaywallInfo: NSObject {
closeReason: PaywallCloseReason,
localNotifications: [LocalNotification],
computedPropertyRequests: [ComputedPropertyRequest],
surveys: [Survey]
surveys: [Survey],
presentation: PaywallPresentationInfo
) {
self.databaseId = databaseId
self.identifier = identifier
Expand All @@ -173,6 +177,7 @@ public final class PaywallInfo: NSObject {
self.localNotifications = localNotifications
self.computedPropertyRequests = computedPropertyRequests
self.surveys = surveys
self.presentation = presentation

if eventData != nil {
self.presentedBy = "event"
Expand Down Expand Up @@ -344,7 +349,12 @@ extension PaywallInfo: Stubbable {
closeReason: .manualClose,
localNotifications: [],
computedPropertyRequests: [],
surveys: []
surveys: [],
presentation: .init(
style: .fullscreen,
condition: .checkUserSubscription,
delay: 0
)
)
}
}
Loading

0 comments on commit abbbfaa

Please sign in to comment.