Skip to content

Commit 6ec1034

Browse files
committed
Deprecate StoreSyncService
1 parent f39320f commit 6ec1034

File tree

5 files changed

+63
-17
lines changed

5 files changed

+63
-17
lines changed

RELEASE_NOTES.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ This version makes StoreKitPlus use Swift 6.
1313

1414
As a result of the Swift 6 transition, and due to data race problems, the store services no longer takes a context and keeps it in sync. This must be explicitly handled by the caller.
1515

16-
Furthermore, the service model is drastically simplified in this version. Instead of having multiple service types, `StoreService` handles it all. Instead of composition, you can override any open function to modify the service behavior.
16+
Furthermore, the service model is drastically simplified in this version. Instead of having multiple service types, `StoreService` handles it all.
1717

1818
### ✨ Features
1919

20-
* `StandardProductService` no longer accepts a context, and will no longer keep it in sync.
21-
* `StandardProductPurchaseService` no longer accepts a context, and will no longer keep it in sync.
20+
* `StoreService` has new `.standard` shorthands.
21+
* `StandardStoreService` no longer accepts a context, and will no longer keep it in sync.
2222

2323
### 🗑️ Deprecations
2424

25-
* `StoreProductService` has been deprecated - just use `StoreService` instead.
26-
* `StorePurchaseService` has been deprecated - just use `StoreService` instead.
25+
* `StoreProductService` has been deprecated.
26+
* `StorePurchaseService` has been deprecated.
27+
* `StoreSyncService` has been deprecated.
2728

2829

2930

Sources/StoreKitPlus/Services/StandardStoreService.swift

+30-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88

99
import StoreKit
1010

11+
public extension StoreService where Self == StandardStoreService {
12+
13+
/// Create a service instance for the provided IDs.
14+
///
15+
/// - Parameters:
16+
/// - productIds: The IDs of the products to handle.
17+
static func standard(
18+
productIds: [String]
19+
) -> Self {
20+
.init(productIds: productIds)
21+
}
22+
23+
/// Create a service instance for the provided products.
24+
///
25+
/// - Parameters:
26+
/// - products: The products to handle.
27+
static func standard<Product: ProductRepresentable>(
28+
products: [Product]
29+
) -> Self {
30+
.init(products: products)
31+
}
32+
}
33+
1134
/// This class implements the ``StoreService`` protocol, and
1235
/// can be used to integrate with StoreKit.
1336
///
@@ -30,8 +53,7 @@ open class StandardStoreService: StoreService {
3053
updateTransactionsOnLaunch()
3154
}
3255

33-
/// Create a service instance for the provided `products`,
34-
/// that syncs any changes to the provided `context`.
56+
/// Create a service instance for the provided products.
3557
///
3658
/// - Parameters:
3759
/// - products: The products to handle.
@@ -49,7 +71,9 @@ open class StandardStoreService: StoreService {
4971
try await Product.products(for: productIds)
5072
}
5173

52-
open func purchase(_ product: Product) async throws -> Product.PurchaseResult {
74+
open func purchase(
75+
_ product: Product
76+
) async throws -> Product.PurchaseResult {
5377
#if os(visionOS)
5478
throw StoreServiceError.unsupportedPlatform("This purchase operation is not supported in visionOS: Use @Environment(\\.purchase) instead.")
5579
#else
@@ -75,7 +99,9 @@ open class StandardStoreService: StoreService {
7599
return transactions
76100
}
77101

78-
open func syncStoreData(to context: StoreContext) async throws {
102+
open func syncStoreData(
103+
to context: StoreContext
104+
) async throws {
79105
let products = try await getProducts()
80106
await context.updateProducts(products)
81107
try await restorePurchases()

Sources/StoreKitPlus/Services/StoreService.swift

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,31 @@ import StoreKit
1515
/// Although some operations can be performed directly using
1616
/// StoreKit like `Product.products(for:)`, the service lets
1717
/// you customize any part of the StoreKit integration.
18-
public protocol StoreService: StorePurchaseService, StoreSyncService {
18+
public protocol StoreService: StoreSyncService {
1919

2020
/// Get all available products.
2121
func getProducts() async throws -> [Product]
22+
23+
/// Purchase a certain product.
24+
func purchase(
25+
_ product: Product
26+
) async throws -> Product.PurchaseResult
27+
28+
/// Restore previous purchases.
29+
@discardableResult
30+
func restorePurchases() async throws -> [Transaction]
31+
32+
/// Sync StoreKit products and purchases to a context.
33+
func syncStoreData(
34+
to context: StoreContext
35+
) async throws
2236
}
37+
38+
public extension StoreService {
39+
40+
@available(*, deprecated, message: "You have to pass in a context now.")
41+
func syncStoreData() async throws {
42+
try await syncStoreData(to: .init())
43+
}
44+
}
45+

Sources/StoreKitPlus/_Deprecated/StorePurchaseService.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,5 @@ import StoreKit
1111
@available(*, deprecated, message: "Just use StoreService instead.")
1212
public protocol StorePurchaseService: AnyObject {
1313

14-
func purchase(_ product: Product) async throws -> Product.PurchaseResult
15-
16-
@discardableResult
17-
func restorePurchases() async throws -> [Transaction]
14+
1815
}

Sources/StoreKitPlus/Services/StoreSyncService.swift Sources/StoreKitPlus/_Deprecated/StoreSyncService.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88

99
import StoreKit
1010

11-
/// This protocol can be implemented by any classes that can
12-
/// be used to sync StoreKit purchase & product information.
11+
@available(*, deprecated, message: "Just use StoreService instead.")
1312
public protocol StoreSyncService: AnyObject {
1413

15-
/// Sync StoreKit product and purchase information to a context.
1614
func syncStoreData(
1715
to context: StoreContext
1816
) async throws
1917
}
2018

19+
@available(*, deprecated, message: "Just use StoreService instead.")
2120
public extension StoreSyncService {
2221

2322
@available(*, deprecated, message: "You have to pass in a context now.")

0 commit comments

Comments
 (0)