Skip to content

Commit

Permalink
Merge pull request #234 from superwall/develop
Browse files Browse the repository at this point in the history
3.7.4
  • Loading branch information
yusuftor authored Sep 4, 2024
2 parents f7624a7 + a3743f4 commit 782a000
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 50 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

## 3.7.4

### Fixes

- Fixes rare crash caused by a Combine issue.
- Confirms the assigment to holdouts for implicit placements like `paywall_decline`.
- Tracks the `trigger_fire` event for implicit placements.

## 3.7.3

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ extension Superwall {
// block when it shouldn't. This has to be done only to those triggers that reassign
// the statePublisher. Others like app_launch are fine to skip and users are relying
// on paywallPresentationRequest for those.
let presentationResult = await internallyGetPresentationResult(forEvent: event, isImplicit: true)
let presentationResult = await internallyGetPresentationResult(
forEvent: event,
requestType: .handleImplicitTrigger
)
guard case .paywall = presentationResult else {
return
}
Expand Down
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.7.3
3.7.4
"""
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ extension Superwall {
_ error: PresentationPipelineError,
requestType: PresentationRequestType
) -> PresentationResult {
if requestType != .getImplicitPresentationResult {
if requestType != .paywallDeclineCheck,
requestType != .handleImplicitTrigger {
Logger.debug(
logLevel: .info,
scope: .paywallPresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Superwall {

return await internallyGetPresentationResult(
forEvent: event,
isImplicit: false
requestType: .getPresentationResult
)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ extension Superwall {
/// - requestType: The presentation request type, which will control the flow of the pipeline.
func internallyGetPresentationResult(
forEvent event: Trackable,
isImplicit: Bool
requestType: PresentationRequestType
) async -> PresentationResult {
let eventCreatedAt = Date()

Expand All @@ -90,7 +90,7 @@ extension Superwall {
.explicitTrigger(eventData),
isDebuggerLaunched: false,
isPaywallPresented: false,
type: isImplicit ? .getImplicitPresentationResult : .getPresentationResult
type: requestType
)

return await getPresentationResult(for: presentationRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Superwall {
from rulesOutcome: RuleEvaluationOutcome,
dependencyContainer: DependencyContainer? = nil
) {
if request.flags.type == .getImplicitPresentationResult {
guard request.flags.type.shouldConfirmAssignments else {
return
}
let dependencyContainer = dependencyContainer ?? self.dependencyContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension Superwall {
isDebuggerLaunched: Bool,
dependencyContainer: DependencyContainer? = nil
) {
if request.flags.type == .getImplicitPresentationResult {
guard request.flags.type.shouldConfirmAssignments else {
return
}
let dependencyContainer = dependencyContainer ?? self.dependencyContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ extension Superwall {
case .paywall(let experiment):
return experiment
case .holdout(let experiment):
await activateSession(request: request, rulesOutcome: rulesOutcome)
await attemptTriggerFire(request: request, rulesOutcome: rulesOutcome)
if let unsavedOccurrence = rulesOutcome.unsavedOccurrence {
storage.coreDataManager.save(triggerRuleOccurrence: unsavedOccurrence)
}
errorType = .holdout(experiment)
paywallStatePublisher?.send(.skipped(.holdout(experiment)))
case .noRuleMatch:
await activateSession(request: request, rulesOutcome: rulesOutcome)
await attemptTriggerFire(request: request, rulesOutcome: rulesOutcome)
errorType = .noRuleMatch
paywallStatePublisher?.send(.skipped(.noRuleMatch))
case .eventNotFound:
errorType = .eventNotFound
paywallStatePublisher?.send(.skipped(.eventNotFound))
case let .error(error):
if request.flags.type == .getImplicitPresentationResult ||
request.flags.type == .getPresentationResult {
if request.flags.type.isGettingPresentationResult {
Logger.debug(
logLevel: .error,
scope: .paywallPresentation,
Expand All @@ -64,12 +63,11 @@ extension Superwall {
throw errorType
}

private func activateSession(
private func attemptTriggerFire(
request: PresentationRequest,
rulesOutcome: RuleEvaluationOutcome
) async {
if request.flags.type == .getImplicitPresentationResult ||
request.flags.type == .getPresentationResult {
guard request.flags.type.shouldConfirmAssignments else {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ extension Superwall {
retryCount: requestRetryCount
)
do {
let isForPresentation = !(request.flags.type == .getImplicitPresentationResult
|| request.flags.type == .getPresentationResult)
let isForPresentation = !request.flags.type.isGettingPresentationResult
let delegate = request.flags.type.getPaywallVcDelegateAdapter()

let paywall = try await dependencyContainer.paywallManager.getPaywall(from: paywallRequest)
Expand Down Expand Up @@ -110,8 +109,7 @@ extension Superwall {
return PresentationPipelineError.userIsSubscribed
}

if request.flags.type != .getImplicitPresentationResult &&
request.flags.type != .getPresentationResult {
if !request.flags.type.isGettingPresentationResult {
Logger.debug(
logLevel: .error,
scope: .paywallPresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ extension Superwall {
triggerResult: rulesOutcome.triggerResult
)
return nil
case .getImplicitPresentationResult,
case .handleImplicitTrigger,
.paywallDeclineCheck,
.getPresentationResult:
// We do not track trigger fire for these events (which would result in .paywall)
return nil
case .presentation:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ extension Superwall {
}
case .getPresentationResult:
message += "Superwall.shared.getPresentationResult"
case .getImplicitPresentationResult:
message += "Superwall.shared.getImplicitPresentationResult"
case .handleImplicitTrigger,
.paywallDeclineCheck:
message += "Superwall.shared.handleImplicitTrigger"
}
let eventData = request.presentationInfo.eventData
let debugInfo: [String: Any] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,43 @@ enum PresentationRequestType: Equatable, CustomStringConvertible {
/// Presenting via ``Superwall/register(event:params:handler:feature:)``.
case presentation

/// Getting the paywall view controller via
/// Get the paywall view controller via
/// ``Superwall/getPaywall(forEvent:params:paywallOverrides:delegate:)``.
case getPaywall(PaywallViewControllerDelegateAdapter)

/// Getting the presentation result via ``Superwall/getPresentationResult(forEvent:)``
/// Get the presentation result via ``Superwall/getPresentationResult(forEvent:)``
case getPresentationResult

/// Getting the presentation result from an event that's used internally. Specifically, getting the result
/// of calling `paywall_decline`.
case getImplicitPresentationResult
/// Get the presentation result from an event that's used internally.
case handleImplicitTrigger

/// Get the presentation result for a `paywall_decline` event to decide whether to
/// close the paywall view controller or not.
case paywallDeclineCheck

var isGettingPresentationResult: Bool {
switch self {
case .presentation,
.getPaywall:
return false
case .getPresentationResult,
.handleImplicitTrigger,
.paywallDeclineCheck:
return true
}
}

var shouldConfirmAssignments: Bool {
switch self {
case .presentation,
.getPaywall,
.getPresentationResult,
.handleImplicitTrigger:
return true
case .paywallDeclineCheck:
return false
}
}

var description: String {
switch self {
Expand All @@ -31,7 +58,8 @@ enum PresentationRequestType: Equatable, CustomStringConvertible {
return "getPaywallViewController"
case .getPresentationResult:
return "getPresentationResult"
case .getImplicitPresentationResult:
case .handleImplicitTrigger,
.paywallDeclineCheck:
return "getImplicitPresentationResult"
}
}
Expand All @@ -56,7 +84,8 @@ enum PresentationRequestType: Equatable, CustomStringConvertible {

static func == (lhs: PresentationRequestType, rhs: PresentationRequestType) -> Bool {
switch (lhs, rhs) {
case (.getImplicitPresentationResult, .getImplicitPresentationResult),
case (.handleImplicitTrigger, .handleImplicitTrigger),
(.paywallDeclineCheck, .paywallDeclineCheck),
(.getPresentationResult, .getPresentationResult),
(.presentation, .presentation),
(.getPaywall, .getPaywall):
Expand Down Expand Up @@ -90,7 +119,8 @@ struct PresentationRequest {
return "getPaywall"
case .presentation:
return "register"
case .getImplicitPresentationResult,
case .paywallDeclineCheck,
.handleImplicitTrigger,
.getPresentationResult:
return nil
}
Expand Down
28 changes: 15 additions & 13 deletions Sources/SuperwallKit/Paywall/Presentation/PublicPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,22 @@ extension Superwall {
paywallOverrides: PaywallOverrides? = nil,
isFeatureGatable: Bool
) -> PaywallStatePublisher {
return Future {
let publisher = PassthroughSubject<PaywallState, Never>()
return Deferred {
Future {
let publisher = PassthroughSubject<PaywallState, Never>()

await self.trackAndPresentPaywall(
forEvent: event,
params: params,
paywallOverrides: paywallOverrides,
isFeatureGatable: isFeatureGatable,
publisher: publisher
)
return publisher
}
.flatMap { publisher in
return publisher
await self.trackAndPresentPaywall(
forEvent: event,
params: params,
paywallOverrides: paywallOverrides,
isFeatureGatable: isFeatureGatable,
publisher: publisher
)
return publisher
}
.flatMap { publisher in
return publisher
}
}
.receive(on: DispatchQueue.main)
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ extension PaywallViewController {

let presentationResult = await Superwall.shared.internallyGetPresentationResult(
forEvent: trackedEvent,
isImplicit: true
requestType: .paywallDeclineCheck
)
let paywallPresenterEvent = info.presentedByEventWithName
let presentedByPaywallDecline = paywallPresenterEvent == SuperwallEventObjc.paywallDecline.description
Expand Down
2 changes: 1 addition & 1 deletion SuperwallKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SuperwallKit"
s.version = "3.7.3"
s.version = "3.7.4"
s.summary = "Superwall: In-App Paywalls Made Easy"
s.description = "Paywall infrastructure for mobile apps :) we make things like editing your paywall and running price tests as easy as clicking a few buttons. superwall.com"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ final class ConfirmHoldoutAssignmentOperatorTests: XCTestCase {
XCTAssertTrue(configManager.confirmedAssignment)
}

func test_confirmHoldoutAssignment_holdout_getImplicitPresentationResult() async {
func test_confirmHoldoutAssignment_holdout_handleImplicitTrigger() async {
let dependencyContainer = DependencyContainer()
let configManager = ConfigManagerMock(
options: SuperwallOptions(),
Expand All @@ -153,7 +153,37 @@ final class ConfirmHoldoutAssignmentOperatorTests: XCTestCase {
)

let request = PresentationRequest.stub()
.setting(\.flags.type, to: .getImplicitPresentationResult)
.setting(\.flags.type, to: .handleImplicitTrigger)
Superwall.shared.confirmHoldoutAssignment(
request: request,
from: input,
dependencyContainer: dependencyContainer
)
XCTAssertTrue(configManager.confirmedAssignment)
}

func test_confirmHoldoutAssignment_holdout_paywallDeclineCheck() async {
let dependencyContainer = DependencyContainer()
let configManager = ConfigManagerMock(
options: SuperwallOptions(),
storeKitManager: dependencyContainer.storeKitManager,
storage: dependencyContainer.storage,
network: dependencyContainer.network,
paywallManager: dependencyContainer.paywallManager,
deviceHelper: dependencyContainer.deviceHelper,
factory: dependencyContainer
)
try? await Task.sleep(nanoseconds: 10_000_000)

dependencyContainer.configManager = configManager

let input = RuleEvaluationOutcome(
confirmableAssignment: .init(experimentId: "", variant: .init(id: "", type: .treatment, paywallId: "")),
triggerResult: .holdout(.init(id: "", groupId: "", variant: .init(id: "", type: .treatment, paywallId: "")))
)

let request = PresentationRequest.stub()
.setting(\.flags.type, to: .paywallDeclineCheck)
Superwall.shared.confirmHoldoutAssignment(
request: request,
from: input,
Expand Down
Loading

0 comments on commit 782a000

Please sign in to comment.