Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit bd09930

Browse files
committed
fix: Convert ProductIOS to dictionaries for Kotlin interop
- Cast Product protocol to concrete ProductIOS type before encoding - Use JSONEncoder to serialize ProductIOS/ProductSubscriptionIOS - Convert JSON to dictionaries for Kotlin compatibility - Fixes nested structure issue in cross-language data transfer
1 parent 01f95ed commit bd09930

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Sources/OpenIapModule+ObjC.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,26 @@ import StoreKit
4343
let request = ProductRequest(skus: skus, type: productType)
4444
let result = try await fetchProducts(request)
4545

46+
let encoder = JSONEncoder()
47+
encoder.dateEncodingStrategy = .millisecondsSince1970
48+
4649
switch result {
4750
case .products(let products):
48-
completion(products, nil)
51+
// Cast to concrete type ProductIOS and convert to dictionaries
52+
let productIOS = products?.compactMap { $0 as? ProductIOS }
53+
let dictionaries = try productIOS?.compactMap { product -> [String: Any]? in
54+
let jsonData = try encoder.encode(product)
55+
return try JSONSerialization.jsonObject(with: jsonData) as? [String: Any]
56+
}
57+
completion(dictionaries, nil)
4958
case .subscriptions(let subscriptions):
50-
completion(subscriptions, nil)
59+
// Cast to concrete type ProductSubscriptionIOS and convert to dictionaries
60+
let subscriptionIOS = subscriptions?.compactMap { $0 as? ProductSubscriptionIOS }
61+
let dictionaries = try subscriptionIOS?.compactMap { subscription -> [String: Any]? in
62+
let jsonData = try encoder.encode(subscription)
63+
return try JSONSerialization.jsonObject(with: jsonData) as? [String: Any]
64+
}
65+
completion(dictionaries, nil)
5166
}
5267
} catch {
5368
completion(nil, error)

0 commit comments

Comments
 (0)