From c814d0e3acc94218ef4c96faa228e44b887e22f0 Mon Sep 17 00:00:00 2001 From: Will Taylor Date: Mon, 7 Oct 2024 09:18:44 -0500 Subject: [PATCH] support deferring win-back storekit messages --- Sources/Purchasing/Configuration.swift | 5 +++-- Sources/Support/StoreMessageType.swift | 15 +++++++++++++++ .../StoreKitUnitTests/StoreMessageTypeTests.swift | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Sources/Purchasing/Configuration.swift b/Sources/Purchasing/Configuration.swift index 00083bdb68..826e707d77 100644 --- a/Sources/Purchasing/Configuration.swift +++ b/Sources/Purchasing/Configuration.swift @@ -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 diff --git a/Sources/Support/StoreMessageType.swift b/Sources/Support/StoreMessageType.swift index d3ab8d6fe5..cf417d1f1f 100644 --- a/Sources/Support/StoreMessageType.swift +++ b/Sources/Support/StoreMessageType.swift @@ -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 @@ -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) diff --git a/Tests/StoreKitUnitTests/StoreMessageTypeTests.swift b/Tests/StoreKitUnitTests/StoreMessageTypeTests.swift index cb13031697..0ffefa00cc 100644 --- a/Tests/StoreKitUnitTests/StoreMessageTypeTests.swift +++ b/Tests/StoreKitUnitTests/StoreMessageTypeTests.swift @@ -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 } }