KMPurchaseManager.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // KMPurchaseManager.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/6/1.
  6. //
  7. import Cocoa
  8. #if VERSION_DMG
  9. #endif
  10. typealias KMPurchaseCompletion = (_ isSuccess: Bool, _ error: String) -> Void
  11. typealias KMPurchaseFetchProductCompletion = (_ isSuccess: Bool, _ products: Array<Any>, _ error: String?) -> Void
  12. class KMPurchaseManager: NSObject {
  13. public static let manager = KMPurchaseManager()
  14. var availableProducts: [KMProduct] = []
  15. override init() {
  16. super.init()
  17. // self.fetchProducts { isSuccess, products, error in
  18. // if isSuccess {
  19. // print("获取产品成功")
  20. // } else {
  21. // print("获取产品失败")
  22. // }
  23. // print(products)
  24. // }
  25. }
  26. func fetchProducts(completeion: @escaping KMPurchaseFetchProductCompletion) {
  27. print("获取产品中")
  28. #if VERSION_FREE
  29. print("正在获取产品中AppStore")
  30. KMInAppPurchaseManager.manager.fetchProducts(completion: completeion)
  31. #endif
  32. #if VERSION_DMG
  33. print("正在获取产品中DMG")
  34. KMDMGPurchaseManager.manager.fetchProducts(completion: completeion)
  35. #endif
  36. }
  37. func purchaseProduct(productIdentifier: String, completion: @escaping KMPurchaseCompletion) {
  38. print("准备订阅中")
  39. #if VERSION_FREE
  40. print("正在订阅中AppStore")
  41. KMInAppPurchaseManager.manager.purchaseProduct(productIdentifier: productIdentifier, completion: completion)
  42. #endif
  43. #if VERSION_DMG
  44. print("正在订阅中DMG")
  45. KMDMGPurchaseManager.manager.purchaseProduct(productIdentifier: productIdentifier, completion: completion)
  46. #endif
  47. }
  48. }