Hi everyone,
I used In-App Purchase in Independent watchOS App as following SwiftUI code but I cannot get products. It seems that the 'SKProductsRequestDelegate' and 'SKRequestDelegate' protocol are not called.
Please tell me the ways if you used to use IAP in Independent watchOS App in SwiftUI (watchOS 6.2+). Thanks
(My code worked on iOS app (companion version))
I used In-App Purchase in Independent watchOS App as following SwiftUI code but I cannot get products. It seems that the 'SKProductsRequestDelegate' and 'SKRequestDelegate' protocol are not called.
Please tell me the ways if you used to use IAP in Independent watchOS App in SwiftUI (watchOS 6.2+). Thanks
(My code worked on iOS app (companion version))
Code Block class IAPManager: NSObject, ObservableObject { static let shared = IAPManager() let purchasePublisher = PassthroughSubject<(String, Bool), Never>() var totalRestoredPurchases = 0 var purchaseHandler : ((String,Bool)->Void)? = nil private override init() { super.init() } func returnProductIDs() -> [String] { return ["com.sample.package01"] } func getProductsV5() { let productIDs = Set<String>(returnProductIDs()) if #available(watchOSApplicationExtension 6.2, *) { let request = SKProductsRequest(productIdentifiers: productIDs) request.delegate = self request.start() } else { // Fallback on earlier versions print("This feature is not supported!") } }
Code Block extension IAPManager: SKProductsRequestDelegate, SKRequestDelegate { func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) { let badProducts = response.invalidProductIdentifiers let goodProducts = response.products if goodProducts.count > 0 { ProductsDB.shared.items = response.products print("bon ",ProductsDB.shared.items) } print("badProducts ",badProducts) } func request(_ request: SKRequest, didFailWithError error: Error) { print("didFailWithError ",error.localizedDescription) purchasePublisher.send(("Purchase request failed ",true)) } func requestDidFinish(_ request: SKRequest) { print("request did finish") } }