Skip to content

Commit

Permalink
Merge pull request #103 from superwall-me/develop
Browse files Browse the repository at this point in the history
v3.0.0-beta.2
  • Loading branch information
yusuftor authored Jan 27, 2023
2 parents cc0d80b + 3b9b88e commit d1ff196
Show file tree
Hide file tree
Showing 185 changed files with 1,493 additions and 1,477 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@

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

## 3.0.0 (Upcoming Release)
## 3.0.0-beta.2

### Breaking Changes

- Moves all functions and variables to the `shared` instance for consistency, e.g. it's now `Superwall.shared.track()` instead of `Superwall.track()`.

### Enhancements

- Readds `Superwall.shared.logLevel` as a top level static convenience variable so you can easily change the log level.
- Adds `isLoggedIn` to user properties, which means you can create a rule based on whether the user is logged in vs. whether they're anonymous.

### Fixes

- Fixes bug in `<iOS 14` where the spinner wasn't appearing when transacting.
- Fixes bug where PaywallOverrides weren't being passed in to the paywall.
- Fixes bug where purchasing, deleting then reinstalling your app, and tapping a purchase button would throw an error.
- Fixes an rare crash associated with the loading and saving of Core Data.

## 3.0.0-beta.1

Welcome to `SuperwallKit` v3.0, the framework formally known as `Paywall`!

Expand Down
6 changes: 3 additions & 3 deletions Examples/SwiftUI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ The SDK sends back events received from the paywall via the delegate methods in

## Logging In

On the welcome screen, enter your name in the **text field**. This saves to the Superwall user attributes using [Superwall.setUserAttributes(_:)](Superwall-SwiftUI/Services/SuperwallService.swift#L62). You don't need to set user attributes, but it can be useful if you want to create a rule to present a paywall based on a specific attribute you've set. You can also recall user attributes on your paywall to personalise the messaging.
On the welcome screen, enter your name in the **text field**. This saves to the Superwall user attributes using [Superwall.shared.setUserAttributes(_:)](Superwall-SwiftUI/Services/SuperwallService.swift#L62). You don't need to set user attributes, but it can be useful if you want to create a rule to present a paywall based on a specific attribute you've set. You can also recall user attributes on your paywall to personalise the messaging.

Tap **Log In**. This logs the user in to Superwall (with a hardcoded userId that we've set), retrieving any paywalls that have already been assigned to them. If you were to create a new account you'd use `Superwall.createAccount(userId:)` instead.
Tap **Log In**. This logs the user in to Superwall (with a hardcoded userId that we've set), retrieving any paywalls that have already been assigned to them. If you were to create a new account you'd use `Superwall.shared.createAccount(userId:)` instead.

You'll see an overview screen:

Expand All @@ -69,7 +69,7 @@ On the [Superwall Dashboard](https://superwall.com/dashboard) you add this event

When an event is tracked, SuperwallKit evaluates the rules associated with it to determine whether or not to show a paywall. Note that if the delegate method [isUserSubscribed()](Superwall-SwiftUI/SuperwallService.swift#L81) returns `true`, a paywall will not show by default.

By calling [Superwall.track(event:params:paywallOverrides:paywallHandler:)](Superwall-SwiftUI/TrackEventModel.swift#L15), you present a paywall in response to the event. For this app, the event is called "MyEvent".
By calling [Superwall.shared.track(event:params:paywallOverrides:paywallHandler:)](Superwall-SwiftUI/TrackEventModel.swift#L15), you present a paywall in response to the event. For this app, the event is called "MyEvent".

On screen you'll see some explanatory text and a button that tracks an event:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ final class StoreKitService: NSObject, ObservableObject {
// MARK: - SKPaymentTransactionObserver
extension StoreKitService: SKPaymentTransactionObserver {
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
restoreCompletion?(true)
}
restoreCompletion?(true)
}

func paymentQueue(
_ queue: SKPaymentQueue,
restoreCompletedTransactionsFailedWithError error: Error
) {
restoreCompletion?(false)
}
func paymentQueue(
_ queue: SKPaymentQueue,
restoreCompletedTransactionsFailedWithError error: Error
) {
restoreCompletion?(false)
}

func paymentQueue(
_ queue: SKPaymentQueue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class SuperwallService {
static let apiKey = "pk_e6bd9bd73182afb33e95ffdf997b9df74a45e1b5b46ed9c9"
static let shared = SuperwallService()
static var name: String {
return Superwall.userAttributes["firstName"] as? String ?? ""
return Superwall.shared.userAttributes["firstName"] as? String ?? ""
}
var isLoggedIn = CurrentValueSubject<Bool, Never>(false)

Expand All @@ -33,12 +33,12 @@ final class SuperwallService {
// }

// Getting our logged in status to Superwall.
shared.isLoggedIn.send(Superwall.isLoggedIn)
shared.isLoggedIn.send(Superwall.shared.isLoggedIn)
}

static func logIn() async {
do {
try await Superwall.logIn(userId: "abc")
try await Superwall.shared.logIn(userId: "abc")
} catch let error as IdentityError {
switch error {
case .missingUserId:
Expand All @@ -53,7 +53,7 @@ final class SuperwallService {

static func logOut() async {
do {
try await Superwall.logOut()
try await Superwall.shared.logOut()
} catch LogoutError.notLoggedIn {
print("The user is not logged in")
} catch {
Expand All @@ -62,11 +62,11 @@ final class SuperwallService {
}

static func handleDeepLink(_ url: URL) {
Superwall.handleDeepLink(url)
Superwall.shared.handleDeepLink(url)
}

static func setName(to name: String) {
Superwall.setUserAttributes(["firstName": name])
Superwall.shared.setUserAttributes(["firstName": name])
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/SwiftUI/Superwall-SwiftUI/TrackEventModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class TrackEventModel {
// private var cancellable: AnyCancellable?

func trackEvent() {
Superwall.track(event: "MyEvent") { paywallState in
Superwall.shared.track(event: "MyEvent") { paywallState in
switch paywallState {
case .presented(let paywallInfo):
print("paywall info is", paywallInfo)
Expand Down
6 changes: 3 additions & 3 deletions Examples/UIKit+RevenueCat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ The SDK sends back events received from the paywall via the delegate methods in

## Logging In

On the welcome screen, enter your name in the **text field**. This saves to the Superwall user attributes using [Superwall.setUserAttributes(_:)](Superwall-UIKit+RevenueCat/PaywallManager.swift#L97). You don't need to set user attributes, but it can be useful if you want to create a rule to present a paywall based on a specific attribute you've set. You can also recall user attributes on your paywall to personalise the messaging.
On the welcome screen, enter your name in the **text field**. This saves to the Superwall user attributes using [Superwall.shared.setUserAttributes(_:)](Superwall-UIKit+RevenueCat/PaywallManager.swift#L97). You don't need to set user attributes, but it can be useful if you want to create a rule to present a paywall based on a specific attribute you've set. You can also recall user attributes on your paywall to personalise the messaging.

Tap **Log In**. This logs the user in to Superwall (with a hardcoded userId that we've set), retrieving any paywalls that have already been assigned to them. If you were to create a new account you'd use `Superwall.createAccount(userId:)` instead.
Tap **Log In**. This logs the user in to Superwall (with a hardcoded userId that we've set), retrieving any paywalls that have already been assigned to them. If you were to create a new account you'd use `Superwall.shared.createAccount(userId:)` instead.

You'll see an overview screen:

Expand All @@ -71,7 +71,7 @@ On the [Superwall Dashboard](https://superwall.com/dashboard) you add this event

When an event is tracked, SuperwallKit evaluates the rules associated with it to determine whether or not to show a paywall. Note that if the delegate method [isUserSubscribed()](Superwall-UIKit+RevenueCat/PaywallManager.swift#L163) returns `true`, a paywall will not show by default.

By calling [Superwall.track(event:params:paywallOverrides:paywallHandler:)](Superwall-UIKit+RevenueCat/TrackEventViewController.swift#L59), you present a paywall in response to the event. For this app, the event is called "MyEvent".
By calling [Superwall.shared.track(event:params:paywallOverrides:paywallHandler:)](Superwall-UIKit+RevenueCat/TrackEventViewController.swift#L59), you present a paywall in response to the event. For this app, the event is called "MyEvent".

On screen you'll see some explanatory text and a button that tracks an event:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/RevenueCat/purchases-ios.git",
"state": {
"branch": null,
"revision": "b1132d43125832409934f0fe5c8642ceb37d60b9",
"version": "4.14.3"
"revision": "390073e0dec72f2a4aabb1888ceda46a059808e5",
"version": "4.17.3"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Combine
final class PaywallManager: NSObject {
static let shared = PaywallManager()
static var name: String {
return Superwall.userAttributes["firstName"] as? String ?? ""
return Superwall.shared.userAttributes["firstName"] as? String ?? ""
}
@Published var isSubscribed = false {
didSet {
Expand Down Expand Up @@ -59,11 +59,11 @@ final class PaywallManager: NSObject {
/// Logs the user in to both RevenueCat and Superwall with the specified `userId`.
///
/// Call this when your user needs to log in.
static func logIn(userId: String) async {
func logIn(userId: String) async {
do {
let (customerInfo, _) = try await Purchases.shared.logIn(userId)
shared.updateSubscriptionStatus(using: customerInfo)
try await Superwall.logIn(userId: userId)
updateSubscriptionStatus(using: customerInfo)
try await Superwall.shared.logIn(userId: userId)
} catch let error as IdentityError {
switch error {
case .alreadyLoggedIn:
Expand All @@ -83,7 +83,7 @@ final class PaywallManager: NSObject {
do {
let customerInfo = try await Purchases.shared.logOut()
updateSubscriptionStatus(using: customerInfo)
try await Superwall.logOut()
try await Superwall.shared.logOut()
} catch let error as LogoutError {
switch error {
case .notLoggedIn:
Expand All @@ -99,18 +99,18 @@ final class PaywallManager: NSObject {
/// [See here](https://docs.superwall.com/v3.0/docs/in-app-paywall-previews#handling-deep-links)
/// for information on how to call this function in your app.
static func handleDeepLink(_ url: URL) {
Superwall.handleDeepLink(url)
Superwall.shared.handleDeepLink(url)
}

/// Settting Superwall attributes.
static func setName(to name: String) {
Superwall.setUserAttributes(["firstName": name])
Superwall.shared.setUserAttributes(["firstName": name])
}

/// Purchases a product with RevenueCat.
/// - Returns: A boolean indicating whether the user cancelled or not.
private func purchase(_ product: SKProduct) async throws -> Bool {
let product = await Purchases.shared.products([product.productIdentifier]).first!
let product = RevenueCat.StoreProduct(sk1Product: product)
let (_, customerInfo, userCancelled) = try await Purchases.shared.purchase(product: product)
updateSubscriptionStatus(using: customerInfo)
return userCancelled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class TrackEventViewController: UIViewController {
}

@IBAction private func trackEvent() {
Superwall.track(event: "MyEvent") { paywallState in
Superwall.shared.track(event: "MyEvent") { paywallState in
switch paywallState {
case .presented(let paywallInfo):
print("paywall info is", paywallInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class WelcomeViewController: UIViewController {
super.viewDidLoad()

isLoggedIn = UserDefaults.standard.bool(forKey: "IsLoggedIn")

if isLoggedIn {
next()
}
Expand All @@ -42,7 +42,7 @@ final class WelcomeViewController: UIViewController {
PaywallManager.setName(to: name)
}
let userId = "abc"
await PaywallManager.logIn(userId: userId)
await PaywallManager.shared.logIn(userId: userId)

next()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)viewWillAppear:(BOOL)animated {

- (IBAction)trackEvent:(id)sender {
__weak typeof(self) weakSelf = self;
[Superwall trackWithEvent:@"MyEvent"
[[Superwall sharedInstance] trackWithEvent:@"MyEvent"
params:nil
products:nil
ignoreSubscriptionStatus:NO
Expand Down
Loading

0 comments on commit d1ff196

Please sign in to comment.