Skip to content

Commit

Permalink
support deferring win-back storekit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-at-will authored Oct 7, 2024
1 parent 7f226d6 commit c814d0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit c814d0e

Please sign in to comment.