Skip to content

Commit

Permalink
Merge pull request #80 from superwall-me/feature/fix-reset-on-bg-thread
Browse files Browse the repository at this point in the history
Feature/fix reset on bg thread
  • Loading branch information
yusuftor authored Oct 17, 2022
2 parents e675e8f + 1c9791c commit 88eb24e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

The changelog for `Paywall`. Also see the [releases](https://github.com/superwall-me/paywall-ios/releases) on GitHub.

## 2.5.3

### Fixes

- Fixes a bug where `Paywall.reset()` couldn't be called on a background thread.


## 2.5.2

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion Paywall.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Paywall"
s.version = "2.5.2"
s.version = "2.5.3"
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
2 changes: 1 addition & 1 deletion Sources/Paywall/Misc/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ let sdkVersion = """
*/

let sdkVersion = """
2.5.2
2.5.3
"""
8 changes: 5 additions & 3 deletions Sources/Paywall/Paywall/Paywall Manager/PaywallCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ final class PaywallCache {
}

func clearCache() {
// don't remove the reference to a presented paywall
for viewController in SWPaywallViewController.cache where !viewController.isActive {
SWPaywallViewController.cache.remove(viewController)
DispatchQueue.main.async {
// don't remove the reference to a presented paywall
for viewController in SWPaywallViewController.cache where !viewController.isActive {
SWPaywallViewController.cache.remove(viewController)
}
}
}
}
44 changes: 23 additions & 21 deletions Tests/PaywallTests/Paywall/Paywall Manager/PaywallCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,36 @@ class PaywallCacheTests: XCTestCase {

func testClearCache() {
// Given
let paywallId1 = "id1"
let key1 = PaywallCacheLogic.key(forIdentifier: paywallId1)
let paywall1: SWPaywallViewController = .stub()
.setting(\.cacheKey, to: key1)
DispatchQueue.main.async {
let paywallId1 = "id1"
let key1 = PaywallCacheLogic.key(forIdentifier: paywallId1)
let paywall1: SWPaywallViewController = .stub()
.setting(\.cacheKey, to: key1)

let paywallId2 = "id2"
let key2 = PaywallCacheLogic.key(forIdentifier: paywallId2)
let paywall2: SWPaywallViewController = .stub()
.setting(\.cacheKey, to: key2)
let paywallId2 = "id2"
let key2 = PaywallCacheLogic.key(forIdentifier: paywallId2)
let paywall2: SWPaywallViewController = .stub()
.setting(\.cacheKey, to: key2)

// When
SWPaywallViewController.cache.insert(paywall1)
SWPaywallViewController.cache.insert(paywall2)
// When
SWPaywallViewController.cache.insert(paywall1)
SWPaywallViewController.cache.insert(paywall2)

let cachedPaywall1 = paywallCache.getPaywall(withKey: key1)
let cachedPaywall2 = paywallCache.getPaywall(withKey: key2)
let cachedPaywall1 = self.paywallCache.getPaywall(withKey: key1)
let cachedPaywall2 = self.paywallCache.getPaywall(withKey: key2)

XCTAssertEqual(cachedPaywall1, paywall1)
XCTAssertEqual(cachedPaywall2, paywall2)
XCTAssertEqual(cachedPaywall1, paywall1)
XCTAssertEqual(cachedPaywall2, paywall2)

paywallCache.clearCache()
self.paywallCache.clearCache()

// Then
let nilPaywall1 = paywallCache.getPaywall(withKey: key1)
let nilPaywall2 = paywallCache.getPaywall(withKey: key2)
// Then
let nilPaywall1 = self.paywallCache.getPaywall(withKey: key1)
let nilPaywall2 = self.paywallCache.getPaywall(withKey: key2)

XCTAssertNil(nilPaywall1)
XCTAssertNil(nilPaywall2)
XCTAssertNil(nilPaywall1)
XCTAssertNil(nilPaywall2)
}
}

func testViewControllers() {
Expand Down

0 comments on commit 88eb24e

Please sign in to comment.