|
@@ -47,6 +47,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
public static let manager = KMInAppPurchaseManager()
|
|
|
|
|
|
var fetchProductCompletion: KMPurchaseFetchProductCompletion?
|
|
|
+ var purchaseProductCompletion: KMPurchaseCompletion?
|
|
|
var availableProducts: [SKProduct] = []
|
|
|
var request: SKProductsRequest?
|
|
|
|
|
@@ -109,6 +110,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
}
|
|
|
|
|
|
func purchaseProduct(productIdentifier: String, completion: @escaping KMPurchaseCompletion) {
|
|
|
+ self.purchaseProductCompletion = completion
|
|
|
if SKPaymentQueue.canMakePayments() {
|
|
|
if let product = availableProducts.first(where: { $0.productIdentifier == productIdentifier }) {
|
|
|
print("\("购买产品") + \(productIdentifier)")
|
|
@@ -117,17 +119,25 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
} else {
|
|
|
// 未找到匹配的产品
|
|
|
print("未找到匹配的产品")
|
|
|
- let tempProductIdentifier = productIdentifier
|
|
|
- self.fetchProducts(completion: { [unowned self] isSuccess, products, error in
|
|
|
- if isSuccess {
|
|
|
- print("获取产品成功")
|
|
|
- self.purchaseProduct(productIdentifier: tempProductIdentifier, completion: completion)
|
|
|
- } else {
|
|
|
- print("获取产品失败")
|
|
|
- }
|
|
|
- })
|
|
|
+ if availableProducts.isEmpty {
|
|
|
+ let tempProductIdentifier = productIdentifier
|
|
|
+ self.fetchProducts(completion: { [unowned self] isSuccess, products, error in
|
|
|
+ if isSuccess {
|
|
|
+ purchaseProductCompletion?(true,"")
|
|
|
+ print("获取产品成功")
|
|
|
+// self.purchaseProduct(productIdentifier: tempProductIdentifier, completion: completion)
|
|
|
+ } else {
|
|
|
+ purchaseProductCompletion?(false,"获取产品失败")
|
|
|
+ print("获取产品失败")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ purchaseProductCompletion?(false,"未找到对应产品")
|
|
|
+ print("未找到对应产品")
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
+ purchaseProductCompletion?(false,"用户无法进行内购")
|
|
|
print("用户无法进行内购")
|
|
|
}
|
|
|
}
|