Skip to content

Instantly share code, notes, and snippets.

@ren6
Created June 18, 2019 09:44
Show Gist options
  • Save ren6/653e4f391da21fd486021266340673be to your computer and use it in GitHub Desktop.
Save ren6/653e4f391da21fd486021266340673be to your computer and use it in GitHub Desktop.
// Starts products loading and sets transaction observer delegate
@objc func startWith(arrayOfIds : Set<String>!, sharedSecret : String){
SKPaymentQueue.default().add(self)
self.sharedSecret = sharedSecret
self.productIds = arrayOfIds
loadProducts()
}
private func loadProducts(){
let request = SKProductsRequest.init(productIdentifiers: productIds)
request.delegate = self
request.start()
}
public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
products = response.products
DispatchQueue.main.async {
NotificationCenter.default.post(name: IAP_PRODUCTS_DID_LOAD_NOTIFICATION, object: nil)
}
}
func request(_ request: SKRequest, didFailWithError error: Error){
print("error: \(error.localizedDescription)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment