Compare commits

...

3 Commits
0.0.1 ... main

Author SHA1 Message Date
zeng
b6cbce9af8 2 2025-12-18 16:17:51 +08:00
zeng
10a0faae95 1 2025-12-18 16:16:20 +08:00
zeng
c0d12ce636 no message 2025-12-18 16:14:32 +08:00
2 changed files with 25 additions and 25 deletions

View File

@ -3,7 +3,7 @@
Pod::Spec.new do |spec| Pod::Spec.new do |spec|
spec.name = "JXIAPManager" spec.name = "JXIAPManager"
spec.version = "0.0.1" spec.version = "0.0.3"
spec.summary = "JXIAPManager内购小工具" spec.summary = "JXIAPManager内购小工具"
spec.description = <<-DESC spec.description = <<-DESC

View File

@ -1,34 +1,34 @@
import UIKit import UIKit
import StoreKit import StoreKit
@objc public protocol JXIAPManagerDelegate { public protocol JXIAPManagerDelegate: AnyObject {
/// ///
@objc optional func jx_iapPaySuccess(productId: String, receipt: String, transactionIdentifier: String) func jx_iapPaySuccess(productId: String, receipt: String, transactionIdentifier: String)
/// ///
@objc optional func jx_iapPayFailed(productId: String, code: JXIAPManagerCode, msg: String?) func jx_iapPayFailed(productId: String, code: JXIAPManager.ErrorCode, msg: String?)
/// ///
@objc optional func iapPayRestore(productIds: [String], transactionIds: [String]) func iapPayRestore(productIds: [String], transactionIds: [String])
// ///
// @objc optional func iapPayShowHud()
// ///
// @objc optional func iapSysWrong()
// ///
// @objc optional func verifySuccess()
// ///
// @objc optional func verifyFailed()
} }
@objc public enum JXIAPManagerCode: Int { public extension JXIAPManagerDelegate {
///
case unknown func jx_iapPaySuccess(productId: String, receipt: String, transactionIdentifier: String) {}
/// func jx_iapPayFailed(productId: String, code: JXIAPManager.ErrorCode, msg: String?) {}
case cancelled func iapPayRestore(productIds: [String], transactionIds: [String]) {}
///
case noProduct
} }
public class JXIAPManager: NSObject { public class JXIAPManager: NSObject {
public enum ErrorCode {
///
case unknown
///
case cancelled
///
case noProduct
}
public static let manager: JXIAPManager = JXIAPManager() public static let manager: JXIAPManager = JXIAPManager()
@ -91,7 +91,7 @@ extension JXIAPManager: SKProductsRequestDelegate {
DispatchQueue.main.async { DispatchQueue.main.async {
if let productId = self.productId { if let productId = self.productId {
self.productId = nil self.productId = nil
self.delegate?.jx_iapPayFailed?(productId: productId, code: .noProduct, msg: nil) self.delegate?.jx_iapPayFailed(productId: productId, code: .noProduct, msg: nil)
} }
} }
return return
@ -155,7 +155,7 @@ extension JXIAPManager {
guard let productId = self.productId, productId == transaction.payment.productIdentifier else { return } guard let productId = self.productId, productId == transaction.payment.productIdentifier else { return }
self.productId = nil self.productId = nil
self.delegate?.jx_iapPaySuccess?(productId: productId, receipt: encodeStr, transactionIdentifier: transactionIdentifier) self.delegate?.jx_iapPaySuccess(productId: productId, receipt: encodeStr, transactionIdentifier: transactionIdentifier)
} }
@ -166,9 +166,9 @@ extension JXIAPManager {
switch error?.code { switch error?.code {
case SKError.paymentCancelled: case SKError.paymentCancelled:
self.delegate?.jx_iapPayFailed?(productId: productId, code: .cancelled, msg: error?.localizedDescription) self.delegate?.jx_iapPayFailed(productId: productId, code: .cancelled, msg: error?.localizedDescription)
default: default:
self.delegate?.jx_iapPayFailed?(productId: productId, code: .unknown, msg: error?.localizedDescription) self.delegate?.jx_iapPayFailed(productId: productId, code: .unknown, msg: error?.localizedDescription)
} }
} }