Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAT-1726: Support Deferring Win-Back StoreKit Messages #4343

Merged
merged 14 commits into from
Oct 7, 2024
5 changes: 3 additions & 2 deletions Sources/Purchasing/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ import Foundation
}

/// Set `showStoreMessagesAutomatically`. Enabled by default.
/// If enabled, if the user has billing issues, has yet to accept a price increase consent or
/// there are other messages from StoreKit, they will be displayed automatically when the app is initialized.
/// If enabled, if the user has billing issues, has yet to accept a price increase consent, is eligible for a
/// win-back offer, or there are other messages from StoreKit, they will be displayed automatically when
/// the app is initialized.
///
/// If you want to disable this behavior so that you can customize when these messages are shown, make sure
/// you configure the SDK as early as possible in the app's lifetime, otherwise messages will be displayed
Expand Down
15 changes: 15 additions & 0 deletions Sources/Support/StoreMessageType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import StoreKit

/// Message shown when there are billing issues in a subscription
case billingIssue = 0

/// Message shown when there is a price increase in a subscription that requires consent
case priceIncreaseConsent

/// Generic Store messages
case generic

/// Message shown when a subscriber is eligible to redeem a win-back offer that you've
/// configured in App Store Connect. More information can be found
/// [here](https://developer.apple.com/documentation/storekit/message/reason/4418230-winbackoffer).
case winBackOffer
}

#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
Expand All @@ -40,6 +47,14 @@ extension Message.Reason {
case .priceIncreaseConsent: return .priceIncreaseConsent
case .generic: return .generic
default:
// winBackOffer message reason was added in iOS 18.0, but it's not recognized by xcode versions <16.0.
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes
#if compiler(>=6.0)
if #available(iOS 18.0, visionOS 2.0, *), case .winBackOffer = self {
return .winBackOffer
}
#endif

// billingIssue message reason was added in iOS 16.4, but it's not recognized by older xcode versions.
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes
#if swift(>=5.8)
Expand Down
6 changes: 6 additions & 0 deletions Tests/StoreKitUnitTests/StoreMessageTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class StoreMessagesTypeTests: TestCase {
#endif
expect(Message.Reason.priceIncreaseConsent.messageType) == .priceIncreaseConsent
expect(Message.Reason.generic.messageType) == .generic

#if compiler(>=6.0)
if #available(iOS 18.0, visionOS 2.0, *) {
expect(Message.Reason.winBackOffer.messageType) == .winBackOffer
}
#endif
}

}
Expand Down