Slide 20
Slide 20 text
購⼊処理フロー/商品情報の取得 .. 旧StoreKitの場合
public typealias ProductsRequestResult = Result
public typealias ProductsRequestCompletion = (ProductsRequestResult) -> Void
public class ProductsRequest: NSObject, SKProductsRequestDelegate {
private var completion: ProductsRequestCompletion?
private var request: SKProductsRequest
init(_ productIDs: Set) {
self.request = SKProductsRequest(productIdentifiers: productIDs)
}
public func send(completion: @escaping ProductsRequestCompletion) {
self.completion = completion
self.request.delegate = self
self.request.start()
}
public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
if let completion = completion {
self.completion = nil
completion(.success(response))
}
}
public func request(_ request: SKRequest, didFailWithError error: Error) {
if let completion = completion {
self.completion = nil
completion(.failure(error))
}
}
}