-
-
Save sergey-zhuravel/ba38cc9d3725daadff280a845c5972c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import StoreKit | |
class IAPManager: NSObject { | |
static let shared = IAPManager() | |
let PREMIUM_MONTH_PRODUCT_ID = "com.test.month" | |
let PREMIUM_YEAR_PRODUCT_ID = "com.test.year" | |
fileprivate var productsRequest = SKProductsRequest() | |
fileprivate var iapProducts = [SKProduct]() | |
// MARK: - FETCH AVAILABLE IAP PRODUCTS | |
func fetchAvailableProducts(){ | |
productsRequest.cancel() | |
// Put here your IAP Products ID's | |
let productIdentifiers = NSSet(objects: PREMIUM_MONTH_PRODUCT_ID, PREMIUM_YEAR_PRODUCT_ID) | |
productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers as! Set<String>) | |
productsRequest.delegate = self | |
productsRequest.start() | |
} | |
} | |
extension IAPManager: SKProductsRequestDelegate { | |
// MARK: - REQUEST IAP PRODUCTS | |
func productsRequest (_ request:SKProductsRequest, didReceive response:SKProductsResponse) { | |
if response.products.count > 0 { | |
iapProducts = response.products | |
for product in iapProducts { | |
print("productIdentifier - ", product.productIdentifier) | |
} | |
} | |
} | |
func request(_ request: SKRequest, didFailWithError error: Error) { | |
print("Error load products", error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment