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 swift(>=6.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the PR description for more details on why this is necessary

Copy link
Member

@MarkVillacampa MarkVillacampa Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the swift compilation condition defines the swift mode, whereas compiler refers to the swift compiler version.

A lot of people will compile in Swift 5.X mode while using Xcode. Since what we actually want to do is detect the Xcode version, and Xcode 16 comes with the Swift 6.0 compiler, it's better to use the compiler condition instead of swift, as we know if ties directly the Xcode version.

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements/#Conditional-Compilation-Block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, TIL! Will switch to using the compiler condition. Thank you!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched in to using the compiler condition in 086dce6 😎

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 swift(>=6.0)
if #available(iOS 18.0, visionOS 2.0, *) {
expect(Message.Reason.winBackOffer.messageType) == .winBackOffer
}
#endif
}

}
Expand Down